invio / invio.extensions.dependencyinjection Goto Github PK
View Code? Open in Web Editor NEWExtensions for DependencyInjection in ASP.NET Core
License: MIT License
Extensions for DependencyInjection in ASP.NET Core
License: MIT License
Travis CI has not yet been updated to use .NET Core v1.1. Code coverage and deployment is performed via appveyor, so it is not a blocking issue. However, we will not be testing to make sure the library works on Linux / Mac OS X with Mono or .NET Core.
The underlying issue from Travis CI is here.
One of the major qualms I have had with the Microsoft dependency injection implementation is that it has a one-type / one-registration policy. If I have two implementations of IFoo
, I cannot register them both simultaneously. Instead, I need to recreate them every time I need them.
StructureMap, because it is not terrible, uses the concept of "named" registrations to get around this problem. When you register an implementation of a service to an interface, you can "name" that registration with a string.
We could add this functionality to the Microsoft implementation by creating some kind of disposable dictionary of type IDictionary<string, TValue>
. For each registration of TValue
, we require a name, and stick it in the dictionary. Then, when the dictionary should be disposed, it disposes all of the TValue
implementations that are IDisposable
.
I could envision it looking something like the following:
services.AddNamedScoped<TService, TImplementation>("Name");
services.AddNamedSingleton<TService>(typeof(TImplementation), "Name");
services.AddNamedTransient(typeof(TService), Func<IServiceProvider, TImplementation>, "Name");
Behind the scenes, this would either create or update a dictionary that had a mapping of names to services that was managed by the Microsoft service provider. When the dictionary would be disposed in accordance to its scope, it disposes its values.
Background
As part of our migration to v1.0.4 of the .NET SDK, I set the DebugType
to full
and updated the CI scripts to explicitly reference XML-based *.csproj
files due to the removal of global.json
and project.json
. The DebugType
really should be portable
for .NET Core when we pack the code (though it needs to be full
for when we run opencover on it), and we should add a *.sln
to manage our *.csproj
files.
Task
Invio.Extensions.DependencyInjection.sln
solution at the root of the repository that references the source and test projects.Invio.Extensions.DependencyInjection.csproj
such that <IsPackable>false</IsPackable>
is specified.set-debug-type.ps1
, but with it updating the DebugType
via the XML-based Invio.Extensions.DependencyInjection.csproj
instead of JSON-based project.json
.The Invio.Extensions.DependencyInjection
library is using the old project.json
format to define its dependencies. We need to migrate it to Invio.Extensions.DependencyInjection.csproj
.
Based upon my research and the results of this stackoverflow question, it does not appear to be possible to use the factory pattern with Microsoft's built in dependency injection pattern. I need to support something like this:
services.AddWithFactory(
new Type[] { Foo, Bar },
typeof(IRepository<>),
typeof(IRepositoryFactory<>),
ServiceLifetime.Singleton
);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.