« first day (3058 days earlier)      last day (2116 days later) » 

14:00
because the InterfacedHttpClient is an adapter for the System.Net.HttpClient class
mr5
mr5
And how does it look like from a utilizing class? How should I instantiate it?
since HttpClient doesnt expose an interface, it is useless
InterfacedHttpClient can be used in DI frameworks
the DI framework can choose if it wants a LoggingClient(InterfacedClient(HttpClient)))
or just an InterfacedClient(HttpClient)
mr5
mr5
err InterfacedHttpClient seems a bit overengineered here
DI framework cannot choose for HttpClient because it does not implement an interface
that is why InterfacedHttpClient is required
mr5
mr5
Yes exactly. So why make it a dependency?
14:03
its not really overengineered
what do you mean with making it a dependency?
mr5
mr5
you are exposing it on this constructor: InterfacedHttpClient(System.Net.Http.HttpClient client) and the utilizer of this class would now be requiring to provide an instance of this where I think is pointless
...since, as you say, it doesn't provide any interfaces at all
"exposing it on this constructor" is irrelevant tho
interface IHttpClient
{
	HttpResponse PostAsync(HttpRequest request);
}
this is an interface, right?
mr5
mr5
ahuh
System.Net.Http.HttpClient doesnt implement this interface, right?
mr5
mr5
ahuh
14:09
I think by "exposing" or "making it a dependency", mr5 means to say "If my class uses an InterfacedHttpClient, it has to also know about the HttpClient now".
Just make the constructor take a Url or something
so your DI framework cannot use HttpClient as implementation for IHttpClient, right?
@Squirrelkiller hmm...
Controller: Wants interface. DI Framework: Injects InterfacedHttpClient. Test mock framework: Injects mocked interface.
a class would never instantiate the InterfacedHttpClient
other than that, go go gadget Law of Demeter
Good point, DI framework does it. jsut realized the same thing.
Law of Demeter is something else afaik
14:12
Although, how does the framework know how to buidl the client
mr5
mr5
This is weird. Why can't it be just directly instantiated inside the wrapper:
class HttpClientWrapper
{
	HttpClient client = new HttpClient(...)
	public HttpResponse PostAsync(...) { }
}
?
it could...
in most cases, it doesnt make any difference
mr5
mr5
It has no where to go if I expose it via constructor
the general difference would be that the wrapper doesnt care where the client comes from
it just wants a client
so, it loads it via the constructor
inversion of dependencies
the one instantiating the clientwrapper could choose to do fancy things with the actual client
maybe have multiple wrappers for one client
mr5
mr5
Err, I think we're talking about composition here.
14:14
it is true that on this level, you might not want to care
but I continue to keep the separation of the instantiation and the usage
the wrapper doesnt care where the actual client came from
so, it doesnt instantiate it, but loads it via the constructor
(I am very fond of Separation of Concerns (SoC))
mr5
mr5
From your previous examples, I thought LoggingHttpClient and AuthenticatedHttpClient already "wraps" the HTTP method calls already. Then you presented another wrapper which seems to me a bit over engineering
the difference is that if you dont use an adapter, the authenticated client cannot wrap the logging client
mr5
mr5
@Wietlol I believe this is true if the HttpClient is just an interface, but in this case, it's a solid implementation.
because if you dont use the adapter, the authenticated client and logging client would not be a nestable decorator (some would say not a decorator at all... Neil for example)
@mr5 HttpClient has varying ways to instantiate it... as you said, you can provide additional arguments in the constructor to do fancy things
this isnt a different type, but still a different implemenation
Afternoon. Doing a bit of research into securing an api in asp.net core. We already have an endpoint that can generate a JWT token, but is it seen as good practice to demand an API key as well?
14:19
so, it also holds true for (sealed) classes, not only for interfaces
mr5
mr5
Okay. Moving on from that, since I wanted the PostAsync<TResult> to automatically deserializes the response data for me, with just a single layer of model, how does LoggingHttpClient and AuthenticatedHttpClient differs from this case? Shouldn't they do the same thing?
logging client has one concern: log http calls
authenticated client has one concern: check if the call would be authenticated, if not, request an authentication before doing the actual call
two concerns, two responsibilities, two classes
logging client and authenticated client dont deal in models, or at least... domain models
mr5
mr5
But HttpClient already provided a constructor for intercepting and I think that is the more suitable place to put the logging. Having that in mind, I think this would create two separate instances of HttpClient
the data client does the serialization and deserialization
@mr5 HttpClient would probably have something built in for many things
however, composition of decorators is much more powerful than anything HttpClient has
mr5
mr5
I cannot visualize how should I design this LoggingHttpClient. It seems to me you are forcing me to do the logging on the PostAsync or GetAsync level.
14:28
and that is what you wanted
you wanted to log all http calls your application does to external services
mr5
mr5
No. I want the logging to be put in the interceptor level, which is, before the SendAsync
HttpClient httpClient = new HttpClient(new DelegatingHandler(new HttpClientHandler()))
DelegatingHandler has an overridable method of SendAsync
hmm...
interface IHttpClient
{
	Task<HttpResponse> SendAsync(HttpRequest request);
}
mr5
mr5
So what I did was LoggingInterceptor : DelegatingHandler
this would probably be a more complete interface for the client
Task<HttpResponse> and SendAsync
    InterfacedHttpClient{
    {
    SendAsync (string content)
      {
        if (this._logger != null) _logger.Log(content)
        this._httpClient.SendAsync(content);
      }
    }
mr5
mr5
14:33
Oh God. Why do you need to use the lowest level. I am only using it for logging.
HttpClientAdapter would probably be a better name...
mr5
mr5
HttpClient already has HTTP Method implementations
but adapters are a combination of an implementation and an interface, naming adapters will always be difficult
or... long... really long
(nvm)
mr5
mr5
You're making my life more difficult Wiet
when you embrace decorators, your life will be easier
14:34
more IoC!
you just have to let go of all primitive and medieval methods
and embrace SoC
Make the logger something independent
inject it into the httpclient when it gets built
but not composition though
mr5
mr5
LoggingHttpClient and AuthenticatedHttpClient can easily be replaced by a: HttpClientWrapper that basically logs every request/response and have a boolean flag which determines if we need an authentication first or not.
@mr5 true, but you are throwing all your responsibilities on one pile
which bites your ass in the future
aggregation
Make the wrapper log if its creator wants it to
mr5
mr5
14:36
I am interested in the AuthenticatedHttpClient but not on the LoggingHttpClient
and how its creator wants it to
mr5
mr5
Maybe you just named it awfully. Let me rename it to NonAuthenticatedHttpClient
There.
ok, so I need a bit of background info, how does the authentication work?
mr5
mr5
It would request first an AccessToken to a certain domain
It would return AccessToken, RefreshToken, and ExpiresIn
ok
lemme see
mr5
mr5
14:39
Then I would use this AccessToken as an Authorization header to every API requests
Can I have that more high level?
When the authenticationHttpClient goes to work, does it authenticate, or is it already authenticated?
no no no, just wait a minute
mr5
mr5
@Squirrelkiller it's not yet authenticated
But you send all requests through it?
mr5
mr5
It would request this AuthData without the Authorization headers set
14:40
So "send this request, but authenticate first plz"
mr5
mr5
Yes. It's publicly available
No
Upon requesting an Authentication, you would pass the username at password in the header
go a bit more high level please
mr5
mr5
Ok. Wait.
the httpclient makes the mheader. You jsut use the client and wanna auth yourself. So you go "yo client auth me with this user and this pw plz" ?
Law of Demeter here. The httpclient knows what a header is. The consumer jsut knows what the authclient is.
Law of Demeter for PresidentOfSoftwareDevelopment
mr5
mr5
The user would logged in to the app where they provide their credentials.
First step is, authenticate this user by passing their credentials into this authentication service.
The authentication service would return an AuthData containing the access token, refresh toke, authorization type, and time of expiry.
Upon having those data, user can now access any APIs just by setting the Authorization headers!
14:44
Ha that name rhymes
Ah so you're in the controller right now? Or in the service?
mr5
mr5
Is that a rap attempt squireliker?
I'm on the service
Controller goes "yo service go login this user", service goes "yo here's some auth data"
ah ok
You fucked up your indentation there Wiet
mr5
mr5
AuthClient.FetchToken();
Which HttpClient does it use?
I'm pretty sure it's a HTTP request.
@Wietlol
14:47
AuthClient would use an IHttpClient (not an AuthenticatedHttpClient)
mr5
mr5
Why is it a solid implementation and not an interface?
what is?
the AuthClient?
mr5
mr5
yeah
it could be an interface
but I am taking it slowly with you guys :)
but the question would be, why would you have different implementations for the AuthClient?
in fact... you could make a generic one
mr5
mr5
So if IAuthService would depend on IHttpClient, it could "mistakenly" use the AuthencticatedHttpClient?
14:51
the DataClient simply wants a mapper (InputModel -> HttpRequest) and (HttpResponse -> OutputModel)
mr5
mr5
The very PostAsync I am thinking of will not expose any of System.Net.Http types. Basically, one level higher.
class DataClient<In, Out>
{
	private IHttpClient Client { get; }
	private Func<In, HttpRequest> InputMapper { get; }
	private Func<HttpResponse, Out> OutputMapper { get; }

	public Task<Out> SendAsync(In inputModel)
	{
		var request = InputMapper.Invoke(inputModel);
		var response = await Client.SendAsync(request);
		var result = OutputMapper.Invoke(response);
		return result;
	}
}
this could be a generic data client
so, the auth client would be DataClient<Void, AuthToken>
@mr5 that is true, but you would find that issue very fast
since every request would then end up with an infinite loop
mr5
mr5
If IAuthService "mistakenly" use the AuthenticatedHttpClient, it would result into an infinite recursion right?
in the ideal situation, when you use the stuff in the same way as they are composed here, every endpoint would have its own client
for each endpoint, you preferably would set the implementation in your DI framework
mr5
mr5
no. That's what I am trying to avoid. I want a single HttpClient instance
14:57
for this, you cannot just use a type based DI framework
@mr5 it is a single instance, just referenced multiple times
var client = new WrappedHttpClient();
DI.Register(endpoint1, client);
DI.Register(endpoint2, client);
DI.Register(endpoint3, client);
DI.Register(endpoint4, client);
DI.Register(endpoint5, client);
...
one instance
^ I dont know if any C# DI framework uses name based injection tho
if you use attribute based registration and name based lookups, you could make an extremely good DI framework
and you could choose to use an authenticated client for some endpoints, and just a raw client for others
mr5
mr5
Okay. That's a good one. But I don't think if that's possible with DryIoc
@Wietlol DryIoc allows a name base injection.
hmm... never heard of it
might be interesting to look into
mr5
mr5
I still think AuthService needs to be an IAuthService for the sake of consistency
consistency is nice
you could, but everytime I say you can never have enough interfaces, I get whacked for it here :)
mr5
mr5
With AuthService having a generic IHttpClient seems to be a hole in your solution.
15:05
you could write a sanity check for it
Dont forget Liskov
but lets try to break it
An IHttpClient needs to work as expected
independent of the actual implementation
var rawClient = new WrappedHttpClient(new HttpClient());
var loggingClient = new LoggingHttpClient(rawClient);
var authenticatedClient = new AuthenticatedHttpClient(loggingClient);

DI.Register(authEndpoint, loggingClient);
DI.Register(userInfoEndpoint, authenticatedClient);
DI.Register(productInfoEndpoint, authenticatedClient);
consider this
mr5
mr5
15:09
@Wietlol hey, that's actually a good one. The only problem is I need to have an instance-based injection rather than types.
6 mins ago, by mr5
With AuthService having a generic IHttpClient seems to be a hole in your solution.
Time for some weekend, see you later when I'll probably be on my pc at home coding again!
mr5
mr5
This still stands through though and might cause a pain in the ass debugging moment
@Squirrelkiller hey want to play dotka?
nah, family wants to play destiny
mr5
mr5
oh wrong request. you're on different continent
but i already installen dotka!
so what? distance isn't important in the age of super fast internet!
15:12
@mr5 now, if the AuthClient would use an authenticatedClient, that means that in your registry, you assigned it an authenticated client
mr5
mr5
Having a party on different continent is unplayable still
> DI.Register(authEndpoint, authenticatedClient);
then, you get the infinite loop
and yes, then it fails
and then you throw a bit of water in your face and fix the error
mr5
mr5
So do you think a sanity check is the solution for that? (Runtime error)
Or we need to add more layer to enforce a compilation error?
Seems wiet also went home. I'mma try to implement that solution now.
Can you generate a compilation error for something that might generate an infinite loop?
I don't think you can, can you?
mr5
mr5
My problem now is I don't have a working endpoint since I'm at home.
15:25
Otherwise you will have solved the halting problem
but something could be said for adding a runtime check
mr5
mr5
It's not what I mean Neil, we could just make another type just so it would not accept IAuthenticatedHttpClient.
Why the shit is it so hard to sort a WPF data grid?
@mr5 So IAuthenticatedHttpClient has an IHttpClient property?
is that it?
mr5
mr5
But that seems to be too complicated so we left the error handling manually
@Neil yeah
why is it being iterated? You trying to serialize it or something?
mr5
mr5
15:27
It's not being iterated. It's recursing infninitely.
I meant, what are you trying to accomplish that would cause it to potentially recurse infinitely?
mr5
mr5
See this Wiet's example at line 28: paste.ofcode.org/V5H6meQeiHAUT2UkEvBknp
AuthClient owns an IHttpClient which means it could be of the same class where the call was residing. And that would render an infinite recursion
is there a serious risk of this happening?
mr5
mr5
My previous problem was a circular dependency. Wiet's solution is better but with this one hole only.
It's probably not even worth the check if you're setting it up statically
mr5
mr5
15:30
No. It's just a nitpicking which can easily be solved in the DI registration
If you're doing some weird dynamic decorating of the IHttpClient, that might make sense to avoid a potential disaster
but otherwise I wouldn't bother
As I see it, if someone creates a self-referencing link by decorating itself, they screwed up, not you
and it's not even the type of problem that might happen once every 30 days or so
you'd know if you messed it up :P
mr5
mr5
Do you find any more flaws in Wiet's solution other than the one I found?
@Neil should the AuthService be AuthService or IAuthService. Should it be a service in the first place since it actually needs no other implementation?
Well typically when you use the decorator pattern, you wrap a single instance of an IHttpClient or whatever you're trying to decorate
It seems his implementation is trying to merge two instances, which could be problematic
if it's easy to do, I'd just port the logic into your decorator class
It's a lot more difficult to create a recursive loop that way as well
mr5
mr5
Authentication process doesn't have a recommendation if you actually needs a separate instance for its HTTP client. My colleagues say, the Authentication service should reside on other domain, different from where the APIs are residing, so this seems to push me into thinking that it really needs to have a separate HttpClient instance since I am not a fan of switching domain address.
It will also solves the circular dependency and recursion from my sol'n and wiet's
But I would have a two HttpClient instance.
mr5
mr5
15:45
Hey
I have an error rare, I define a property like int? and from postman send a request to the service with a property and the value with 4 digits, only there run the error, if I send with 3 digits or 5 digits the error not run.
mr5
mr5
is it int? as in nullable int?
also, what is the actual error message?
You could remove the code if (DigitCount(property) == 4) throw new Exception()
mr5
mr5
lol
!!> [] + {}
15:54
@Sinjai "[object Object]"
!!> {} + []
@Sinjai 0
mr5
mr5
Where can I test HTTP/3 aka QUIC?
!!> ({} + []) === {} + []
@MikeTheLiar true
15:57
!!> {} + [] === ({} + [])
@MikeTheLiar false
sTrIcT EqUaLiTy
mr5
mr5
hey, the first one actually returns an int(double) with a zero value, so it's still "strict" equality
!!>{} + []
@MikeTheLiar 0
16:03
!!> typeof({} + [])
@MikeTheLiar "string"
16:14
i'm getting this error: c# the type child must be convertible to parent
where child is two levels down from the parent. is that not allowed?
Should be. Can you give an example?
yeah.
@mr5 yes nullable int
i've been fighting with many things that should be allowed today. i think unity might be the culprit
@mr5 im not home :(
i was... distracted
(im trying to set up a parameterized pipeline
16:18
@mr5 "Message=Could not load file or assembly 'System.Numerics.Vectors, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified."
Anyone want to take a stab at this for Core.
0
Q: Issue with area route in Asp.Net Core 2.2

GregInside my application I appear to have an issue with my route. I cannot determine why the route would be failing. The solution contains a controller that derives from the [ApiController] to adhere to Web Api standards. Area > > > Devices > > > Sampler (Controller) /api/Devices/Sampler/GetSampl...

mr5
mr5
@FedericoFiaSare hmm, can you try this solution: stackoverflow.com/a/49943288/2304737
@Wietlol nice. are you a devops engineer?
public class BaseListRowController<TModel, TView>: MonoBehaviour
        where TModel : BaseListRowModel
        where TView : BaseListRowView

public class BaseHierarchyListRowController<TModel, TView> :
        BaseListRowController<TModel, TView>,
        IHierarchyListCollapsible
        where TModel : BaseHierarchyListRowModel
        where TView : BaseHierarchyListRowView

public class HierarchyListAreaRowController :
        BaseHierarchyListRowController<HierarchyListAreaRowModel, HierarchyAreaRowView>
that is the hierarchy. idk if it helps. i have a generic function :

public T1 InstantiateChildPrefab<T1>(GameObject childPrefab, Transform childRootTransform = null,
            bool worldPositionStays = false)
        where T1 : BaseListRowController<BaseListRowModel, BaseListRowView>
Trying to call this then:
 InstantiateChildPrefab<HierarchyListAreaRowController>(view.childPrefab, view.childContentRoot.transform, false);
please tell me i'm a idiot and overlooked something obvious bcz i'm tried.
16:25
@mr5 there will be a day that I will know what a devops engineer means, but it is not this day!
mr5
mr5
@Wietlol I actually doesn't know what they really do but I've heard they do less code and more on GUI things. Like setting up CIs
@user14492 is this the offending statement in your code?
can you guys post your internet speed here so I can finally cry?
yesh when i call the function specifying the child type
mr5
mr5
@user14492 what are the suggested quick fix if you hit alt+enter?
to remove the constraint
on function
mr5
mr5
try doing that first and put it back once you have realized something
16:29
but i want constraint bcz i want to be able to call some base type function.... and collect them in a list whose type is the base type
mr5
mr5
it wont hurt if you remove the constraint. we're just trying to solve this phase 1 issue
try a force cast to it and see what happens. that's what I usually do when I have no idea what I'm actually doing.
no it won't but then the code wont compile
mr5
mr5
> view.childPrefab, view.childContentRoot.transform
which one is the type that derives from your base class here?
none.
public T1 InstantiateChildPrefab<T1>(GameObject childPrefab, Transform childRootTransform = null,
            bool worldPositionStays = false)
        where T1 : BaseListRowController<BaseListRowModel, BaseListRowView>
        {
            var childObj = Instantiate(childPrefab, childRootTransform, worldPositionStays);
            var childController = childObj.GetComponent<T1>();
            ChildControllers.Add(childController);
            return childController;
        }
mr5
mr5
T1 is HierarchyListAreaRowController
16:34
which is derieved from BaseListRowController<BaseListRowModel, BaseListRowView>
mr5
mr5
while in your constraint, it's BaseListRowController<BaseListRowModel, BaseListRowView>
as shown above.
mr5
mr5
That seems to be two different types
Why can't it be just HierarchyListAreaRowController instead of BaseListRowController<BaseListRowModel, BaseListRowView>?
bcz i want to be able to call this function with other types that derive from BaseListRowController
public class BaseListRowController<TModel, TView>: MonoBehaviour
        where TModel : BaseListRowModel
        where TView : BaseListRowView

public class BaseHierarchyListRowController<TModel, TView> :
        BaseListRowController<TModel, TView>,
        IHierarchyListCollapsible
        where TModel : BaseHierarchyListRowModel
        where TView : BaseHierarchyListRowView

public class HierarchyListAreaRowController :
        BaseHierarchyListRowController<HierarchyListAreaRowModel, HierarchyAreaRowView>
see how HierarchyListAreaRowController is derived from BaseHierarchyListRowController which is derived from BaseListRowController
mr5
mr5
> public class HierarchyListAreaRowController :
BaseHierarchyListRowController<HierarchyListAreaRowModel, HierarchyAreaRowView>
what's the purpose of that class?
Did you extend any functionality from there?
Or it's just a type declaration?
16:40
yes
mr5
mr5
That's the problem.
HierarchyListAreaRowController != BaseHierarchyListRowController<HierarchyListAreaRowModel, HierarchyAreaRowView>
no as in it extends functionality
@mr5 that solution does not work. My problem is only with number of 4 digits
any other number works
mr5
mr5
@FedericoFiaSare the error message you have provided to me doesn't say so.
Do you have any code like this:
56 mins ago, by Default
You could remove the code if (DigitCount(property) == 4) throw new Exception()
@user14492 can you add more generic type to InstantiateChildPrefab?
yeah ofc. i could make it an object but then i won't be able to access the parts of base class.
mr5
mr5
16:47
public T1 InstantiateChildPrefab<T1, T2, T3>(GameObject childPrefab, Transform childRootTransform = null,
            bool worldPositionStays = false)
        where T1 : BaseListRowController<T1, T2>
        where T2: BaseListRowModel
        where T3: BaseListRowView
@mr5 @mr5 I did the search for that code but I do not have anything similar
mr5
mr5
@FedericoFiaSare can you put a breakpoint on your controller before processing this 4 digit number?
or does it throw before it actually reaches your controller?
how would you redefine this then:
public List<BaseListRowController<BaseListRowModel, BaseListRowView>> ChildControllers { get; set; }
wanna be able to add objects fo any sub class to this list.
@mr5 Yes, it does throw before it actually reaches controller.
mr5
mr5
@FedericoFiaSare have you really tried directly referencing the said DLL instead of NuGet package?
@user14492 which class does it reside?
16:55
same place as the generic function
user10864482
good morning
agh. just 30 more minutes and i can stop pretending to solve this issue. so good evening stranger.
user10864482
what is the issue you are experiencing @user14492
mr5
mr5
@user14492 is this preventing you from compiling again?
yes it is.

« first day (3058 days earlier)      last day (2116 days later) »