Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Dependency Injection #44

Open
Ruhrpottpatriot opened this issue Sep 22, 2017 · 4 comments
Open

Implement Dependency Injection #44

Ruhrpottpatriot opened this issue Sep 22, 2017 · 4 comments

Comments

@Ruhrpottpatriot
Copy link
Owner

Ruhrpottpatriot commented Sep 22, 2017

ref #34 #5

@sliekens
Copy link
Collaborator

sliekens commented Oct 8, 2017

Here's a good blog post from someone much smarter than me: http://blog.ploeh.dk/2014/05/19/di-friendly-library/

Mark wrote a book called Dependency Injection in .NET. I think that every decision here should be based on his book and articles.

@Ruhrpottpatriot
Copy link
Owner Author

I think we should go with the netcore dependency injection. It's simple and easy to used and adapters into more popular frameworks such as Autofac, StructureMap, etc. exist.

Registering modules is done via an extension method (as it is recommended on Github/MSDN), much like this:

public static IServiceCollection AddBuild(this IServiceCollection serviceCollection)
{
    serviceCollection.RegisterScoped<IBuildService, BuildService>();
    serviceCollection.RegisterScoped<IConverter<BuildDto, Build>, BuildConverter>();
    return serviceCollection;
}

This gives us everything we need and we can put everything together in the GW2.NET main app.

I'm just thinking how we can implement configuration for the various parts. In ASP.NET you can do something like this: serviceCollection.AddMvc(opt => { /* Some Options*/ });
whereas the options are of type MvcOptions, which is a class that has multiple properties that control the mvc pipeline. We can do the same for us, but I'm not sure how to get the options to the actual object.

@sliekens
Copy link
Collaborator

sliekens commented Nov 1, 2017

Can this be completely optional? As in you should be able to use a ServiceCollection to resolve services without taking away the option to construct services manually.

@Ruhrpottpatriot
Copy link
Owner Author

Yes and no. The services and converter won't be made into internal/protected classes but will stay public, so the user can choose to manually create an instance of, say, BuildService and BuildConverter. However, does that mean we should encourage him to do so? No, not really.

I'm still thinking how we can make the api endpoints available in a type safe way. I found a way around the configuration problem (enter: Factory, which I totally missed), but not this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants