-
Notifications
You must be signed in to change notification settings - Fork 314
It's not ISSUE but Question #305
Comments
In general, we've been avoiding adding features that don't exist in other DI solutions.
|
I thought the whole point of this was to have a "lowest common denominator" way of registering/resolving framework components and that you could BYOC (Bring Your Own Container) if you wanted more features? Several of the things mentioned are generally viewed as anti-patterns, like property injection (either using an Some of the requirements of this library (see conforming containers) are already alienating several existing .NET IoC containers and they're unable to conform. Adding more features to this list of requirements won't help anyone. So, my 👍 goes to BYOC if you require more features from your IoC container than what this library offers. The current set of features should be more than enough to get by and somewhat enforces good practices like constructor injection 😄 |
Ok. BYOC is way. Property injection can be worst than evil but it's thing that any DI should provide along with ctor injection. So private members binding too if explicitly configured. But it's kind of holywar. |
Moving this to Backlog as we are not planning to make any changes for this at this time. |
After implementing several projects in asp.net core faced with problem that As solution created temporary library DIAttributeRegistrar where in readme named several problems. I agree that all new functionality mentioned in discussion above it's not required as part of |
Nice! The biggest downside is loading all assemblies and scanning all types up front. That will dramatically slow down the startup time (especially as the application grows). You can make this a little smarter https://github.com/IhnatKlimchuk/DIAttributeRegistrar/blob/98b8a3641faf685f64417366b6344ee331bb52c6/src/DIAttributeRegistrar/DIAttributeRegistrarExtentions.cs#L39 by looking at assemblies that depend on the DIAttributeRegistrar package. That way you're not scanning everything by default. |
Thanks @davidfowl for pointing that, will add improvements shortly. Anyway you can pass assemblies to scan by your own. Regarding this discussion, I hope to see new package soon. That definitely should be separate package in order not to decrease base performance. Will be glad to help with it. |
This issue was moved to dotnet/aspnetcore#2352 |
We have own DI/IoC framework in private code. It has 5 years history and primary was inspired by Castle Windsor.
We think that it will be good if aspnet/DI became the only one to decrease entropy of different solutions. But our framework has greatly another functionality rather than current apnet/DI way. If it's interesting we will try supply improved version of DI if it's not.. it's not...
Here is some features we suggest to implement (pseudocode - not real names).
Most of them focused on adaption IoC as plugin centralization and extension point centralization facility.
DI-bound services - service instance can implement plugin-like API
void OnCreateFromContainer(IContainer container, IComponent component)
- so service can realize own DI logic and use container internallyAutomatic assembly and type setup a) classes that implement
IContainerLibrarySetup.Setup(IContainer container)
- can be used as assembly-wide DI setup logic and[ContainerComponentAttribute(lifestyle,...)]
that provide decoration for services that we want to register in container, at Container level there are Container.Register(Assembly assembly); and Container.Register(Type type) extension methodsSupport for multiple mapping
ServiceType -> ServiceImpl*
that allow as not justResolve<S>() but ResolveAll<S>()
notation - so it's simple way to inject collections of some services (it's usual for extensions, filters, subproviders and so on)Dual type-based and name-based registry for components, so we can use both
Resolve<S>() or Resolve(Type t)
andResolve(name) Resolve<S>(name) and Resolve<S>("prefix*")
- this is very usefull if we have multiple services for service interface but for different tasks. For example we have some kind ofIFilter
( bool IsFiltered(object val) )but context of filter is very different. We can use namespace-like name notation and call
ResolveAll("out.type.*")``` to get themExtended
[Inject]
attribute that can decorate Properties, Fields and Method parameters - it can define some hints about how to bind it's target during DI when service is created and allow explicit control how to setup service. So it can provide required name (4) , default factory type (if not container setup) and so onDI not for public only - it can bind privates if it's explicitly required by Inject, DI can work with collections, DI can keep existed collections
In code it looks like:
This is things that we think to realize in aspnet/DI.
If it's interesting - we will fork DI, create set of focused issues and start to setup contribute.
The text was updated successfully, but these errors were encountered: