Description
From @comdiv on Thursday, October 15, 2015 5:07:06 AM
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 internally -
Automatic 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 methods -
Support 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 them -
Extended
[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 on -
DI 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:
[ContainerComponent(Lifiestyle.Singleton)]
class MyServive:IOurService {
[Inject]
protected IList<IOtherService> SubServices {get;}=new List<IOtherService>{new OtherService()};
...
}
var c = new Container();
c.Register<MyService>();
...
c.Resolve<IOurService>(); // internally SubServices will be appended with DI with keeping existed list
...
- Inject API that allow us DI into existed classes, aside of main DI process (Angular DI inspired):
IContainer c = GetMyMainAppContaner(); // it's not really-existed method )))
var myClass = new MyObject();
c.Inject(myClass);
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.
Copied from original issue: aspnet/DependencyInjection#305