These are chat archives for Ruhrpottpatriot/GW2.NET

5th
Oct 2015
Robert Logiewa
@Ruhrpottpatriot
Oct 05 2015 11:03
btw: Shouldn the namespace GW2NET.Factories.V2 be called GW2NET.V2.Factories?
Steven Liekens
@StevenLiekens
Oct 05 2015 11:46
idk
the factories are just temporary anyway
Robert Logiewa
@Ruhrpottpatriot
Oct 05 2015 11:46
yeah I know
Steven Liekens
@StevenLiekens
Oct 05 2015 11:46
they're the glue that holds everything together until we introduce a proper DI framework
did you decide on autofac?
Robert Logiewa
@Ruhrpottpatriot
Oct 05 2015 11:47
not yet
but that is the most likely candidate
I'm still not sure whether we should use Autofac or MEF
Steven Liekens
@StevenLiekens
Oct 05 2015 11:48
well they both have different purposes
Robert Logiewa
@Ruhrpottpatriot
Oct 05 2015 11:48
you can use MEF as DI framework
Steven Liekens
@StevenLiekens
Oct 05 2015 11:49
mef is kinda ugly for that
mef makes you decorate every dependency with attributes
Robert Logiewa
@Ruhrpottpatriot
Oct 05 2015 11:49
not anymore
MEF 2 changed a lot
and that is why I have so many problems with it
it's an entirely new way of thinking
Steven Liekens
@StevenLiekens
Oct 05 2015 11:51
does it support constructor injection?
Robert Logiewa
@Ruhrpottpatriot
Oct 05 2015 11:52
afaik yes
old MEF did that too
Steven Liekens
@StevenLiekens
Oct 05 2015 11:52
without ImportingConstructorAttribute?
Robert Logiewa
@Ruhrpottpatriot
Oct 05 2015 11:52
MEF 2 should be able, from what I read you can now do everything without attributes
Steven Liekens
@StevenLiekens
Oct 05 2015 11:53
good
using RegistrationBuilder?
okay yeah I found a nice code example
that's a lot better than it used to be in MEF 1
still not as "automatic" as some more specialized frameworks
I've never used Autofac, but I've used Ninject
Robert Logiewa
@Ruhrpottpatriot
Oct 05 2015 11:58
Ninject is slow
very slow
Steven Liekens
@StevenLiekens
Oct 05 2015 11:58
really?
Robert Logiewa
@Ruhrpottpatriot
Oct 05 2015 11:59
a bit old, so maybe the speed has changed, but look here: http://www.palmmedia.de/blog/2011/8/30/ioc-container-benchmark-performance-comparison
Steven Liekens
@StevenLiekens
Oct 05 2015 11:59
I can imagine that would be a problem if used as a service locator instead of a container
how the hell is mef 2 so much faster than mef 1
Robert Logiewa
@Ruhrpottpatriot
Oct 05 2015 12:01
but it seems the article is up to date
last change was 19.08.2015
Steven Liekens
@StevenLiekens
Oct 05 2015 12:03
looks like mef2 is a clear winner
Robert Logiewa
@Ruhrpottpatriot
Oct 05 2015 12:12
not entirely
DryIoC is still faster
but I think we should go with MEF 2
which I -btw- totally overlooked
I only saw MEF 1 4.0^^
Robert Logiewa
@Ruhrpottpatriot
Oct 05 2015 12:20
I'm still stinking how I should design the message handlers properly
since they are the ones who do the heavy lifting
Steven Liekens
@StevenLiekens
Oct 05 2015 12:25
I haven't used it enough to be of much help
Robert Logiewa
@Ruhrpottpatriot
Oct 05 2015 12:26
I think I'll replace the old Http classes in IServiceClient at first and the work my way up from there.
Steven Liekens
@StevenLiekens
Oct 05 2015 12:27
wouldn't it be easier to refactor repositories to use HttpClient until there are no more usages of IServiceClient? and then delete it
Robert Logiewa
@Ruhrpottpatriot
Oct 05 2015 12:27
as far as I saw it it is not that easy
the HttpClient doesn't do the connections and retrival, it is all done by the HttpMessageHandler
Steven Liekens
@StevenLiekens
Oct 05 2015 12:28
yea
Robert Logiewa
@Ruhrpottpatriot
Oct 05 2015 12:28
and that is the class that should persist
Steven Liekens
@StevenLiekens
Oct 05 2015 12:28
oh
Robert Logiewa
@Ruhrpottpatriot
Oct 05 2015 12:28
since this class does the connection
see here
Interestingly, HttpClient itself does not do any of the dirty work of making HTTP requests; it defers that job to an aggregated object that derives from HttpMessageHandler.
Steven Liekens
@StevenLiekens
Oct 05 2015 12:29
yea so your handler should wrap WebRequestHandler, right?
Robert Logiewa
@Ruhrpottpatriot
Oct 05 2015 12:30
there is no class WebRequestHandler
it's a class he designed afaik
Steven Liekens
@StevenLiekens
Oct 05 2015 12:30
no there is
Robert Logiewa
@Ruhrpottpatriot
Oct 05 2015 12:30
dafuq
why do I not have it?
Steven Liekens
@StevenLiekens
Oct 05 2015 12:30
it's the default HttpMessageHandler
if you use the default ctor of HttpClient, that's the handler it uses internally
Robert Logiewa
@Ruhrpottpatriot
Oct 05 2015 12:31
err
Provides desktop-specific features not available to Windows Store apps or other environments.
WebRequestHandler is not available in PCL
Steven Liekens
@StevenLiekens
Oct 05 2015 12:31
what's the PCL equivalent?
Robert Logiewa
@Ruhrpottpatriot
Oct 05 2015 12:32
i don't know one
the closest has to be HttpClientHandler
Steven Liekens
@StevenLiekens
Oct 05 2015 12:32
well there's gotta be one
Robert Logiewa
@Ruhrpottpatriot
Oct 05 2015 12:32
WebRequestHandler derives from HttpClientHandler but adds properties that generally only are available on full .NET. The WebRequestHandler is not included in the System.Net.Http DLL but rather in System.Net.Http.WebRequest DLL so you have to explicitly include that as a reference in order to see it. Otherwise it won’t show up.
ah
it is HttpClientHandler
HttpClientHandler is an HttpMessageHandler with a common set of properties that works across most versions of the HttpWebRequest API. This is the default handler and so is what you get if you use the default constructor.
Steven Liekens
@StevenLiekens
Oct 05 2015 12:34
oh
Robert Logiewa
@Ruhrpottpatriot
Oct 05 2015 12:34
so we should derive from that
Steven Liekens
@StevenLiekens
Oct 05 2015 12:34
I thought WebRequestHandler was the default handler
my bad
Robert Logiewa
@Ruhrpottpatriot
Oct 05 2015 12:34
but still it is not that easy
Steven Liekens
@StevenLiekens
Oct 05 2015 12:34
there's a DelegatingHandler too, right?
Robert Logiewa
@Ruhrpottpatriot
Oct 05 2015 12:34
yep
Steven Liekens
@StevenLiekens
Oct 05 2015 12:35
I think that's the one that you should extend
great documentation by the way
Gets or sets {insert text here}.
Robert Logiewa
@Ruhrpottpatriot
Oct 05 2015 12:36
I don't think DelegatingHandler is the right way to go
Steven Liekens
@StevenLiekens
Oct 05 2015 12:36
why not
it's used for pre-/postprocessing of http messages
Robert Logiewa
@Ruhrpottpatriot
Oct 05 2015 12:37
from my understanding it is only used if you have to change the request in a way (e.g. the requested method is not supported, or you want to switch all requests over https), since it only routes the request to the inner handler
A base type for HTTP handlers that delegate the processing of HTTP response messages to another handler, called the inner handler.
Steven Liekens
@StevenLiekens
Oct 05 2015 12:41
public class DateObsessedHandler : DelegatingHandler
{          
    protected async override Task<HttpResponseMessage> SendAsync(
        HttpRequestMessage request, 
        CancellationToken cancellationToken)
    {
        var requestDate = request.Headers.Date;
        // do something with the date ...

        var response =  await base.SendAsync(request, cancellationToken);

        var responseDate = response.Headers.Date;
        // do something with the date ...

        return response;
    }
}
seems like the perfect place to inject header parsing and whatnot
Robert Logiewa
@Ruhrpottpatriot
Oct 05 2015 12:43
yeah, butr I'm still thinking about the response
where should I inject the json conversion
Steven Liekens
@StevenLiekens
Oct 05 2015 12:43
I'm thinking about how to set additional properties on the response
I think I know where to inject the conversion
Robert Logiewa
@Ruhrpottpatriot
Oct 05 2015 12:45
where?
Steven Liekens
@StevenLiekens
Oct 05 2015 12:47
public class BuildSchemaHandler : DelegatingHandler
{          
    protected async override Task<HttpResponseMessage> SendAsync(
        HttpRequestMessage request, 
        CancellationToken cancellationToken)
    {
        var response =  await base.SendAsync(request, cancellationToken);

        BuildDTO dto;
        using (Stream responseStream = await response.Content.ReadAsStreamAsync())
        {
            dto = JsonSerializer.Deserialize(responseStream);
        }

        response.Content = new SomeCustomHttpContentClass(dto);

        return response;
    }
}
Robert Logiewa
@Ruhrpottpatriot
Oct 05 2015 12:47
that should be possible, yes
Steven Liekens
@StevenLiekens
Oct 05 2015 12:49
and the DTO object is also the container for any additional header values
I mean could be
or the custom HttpContent class could have properties for specialized headers
I'm not really sure how it's supposed to be done
just brainstorming here
Robert Logiewa
@Ruhrpottpatriot
Oct 05 2015 12:54
It's supposed to be in the HTTPContent
lemme search the link
the HttpContent class already has a Headers property
and you can add custom headers to it
Steven Liekens
@StevenLiekens
Oct 05 2015 12:57
yeah but where are you supposed to parse the values?
Robert Logiewa
@Ruhrpottpatriot
Oct 05 2015 12:57
which values?
Steven Liekens
@StevenLiekens
Oct 05 2015 12:57
specifically the Link header
Robert Logiewa
@Ruhrpottpatriot
Oct 05 2015 12:58
in the response class
there was an example, that you could for example create a custom message handler that automatically retires or uses a new url in case of a 301
Steven Liekens
@StevenLiekens
Oct 05 2015 13:00
I'm still confused about where in the pipeline you parse the Link header and what to do with the parsed values
Robert Logiewa
@Ruhrpottpatriot
Oct 05 2015 13:01
I think it is all done in the response message handler
Steven Liekens
@StevenLiekens
Oct 05 2015 13:01
so then you have to set the parsed values on the response message somehow
Robert Logiewa
@Ruhrpottpatriot
Oct 05 2015 13:01
yep
Steven Liekens
@StevenLiekens
Oct 05 2015 13:01
custom response type maybe?
Robert Logiewa
@Ruhrpottpatriot
Oct 05 2015 13:02
and for that you create acustom response type
Steven Liekens
@StevenLiekens
Oct 05 2015 13:02
ApiResponseMessage : HttpResponseMessage
with properties for custom headers
Robert Logiewa
@Ruhrpottpatriot
Oct 05 2015 13:02
httpContent is an abstract class anyway
Steven Liekens
@StevenLiekens
Oct 05 2015 13:13
I have to go get ready
Robert Logiewa
@Ruhrpottpatriot
Oct 05 2015 13:13
ok
I'll look into it some more
Robert Logiewa
@Ruhrpottpatriot
Oct 05 2015 22:06
@StevenLiekens I think I know how to handle our "problem". I'll post something more if I have actual code, but if it works like I think it'll work. We should be able to implement it without problems.