[Docs] Does built-in container handle disposal?
I'm using the built-in container like so:
invocationContext.BindingContext.AddService(x => new ParentService());
invocationContext.BindingContext.AddService(x => new ChildService(x.GetRequiredService<ParentService>()));
invocationContext.BindingContext.AddService(x => new OtherService());
// etc.
An IoC container typically handles disposal. I looked at BindingContext and didn't see anything to this effect, but maybe I'm looking in the wrong place.
Does this library's container dispose services that implement IDisposable?
It's not really a container. It doesn't allow open-ended registration, doesn't handle object instantiation, and doesn't handle disposal.
What is "open-ended registration" in this context? Open generic types perhaps?
Open generics aren't supported and type mappings are exact, i.e. if you only register something as IWidget, you can't resolve Widget. Every type must be registered explicitly. It's really intended, at most, as a pass-through to a real container.
If I see "IOC" or "DI" then I automatically assume the above. Other people will also get confused and that will lead to bugs... and unnecessary issues in the repo. :wink:
So at some point this should probably be in the docs:
doesn't allow open generics, doesn't handle object instantiation, and doesn't handle disposal
It might be good to provide guidance for disposal; as above, just to avoid unnecessary issues in the repo. My approach:
- make services implement
IDisposable - make the composition root implement
IDisposable(the class where I callcontext.BindingContext.AddService(x => new FooService()), for me that's inProgram) - in
Program.Dispose()I also dispose all disposable services