CCLLC.Core.IocContainer

The IoCContainer is a lightweight container implementation that supports constructor dependency injection.

Nuget Packages

The CCLLC.Core.IReadOnlyIocContainer interface provides a Resolve<T>() method that searches the container for a registered implementation for the interface type T and then returns that implementation with all constructor dependencies created and injected.

The CCLLC.Core.IocContainer interface extends IReadOnlyIocContainer to add the Implement<T>() method initiate the registration of an implementation. Implement<T>() is the start of a fluent expression that relies on a the _.Using<C>() method do define the implementing class.

For example Container.Implement<IFoo>().Using<Foo>() directs the container to use class Foo to resolve a request for interface IFoo.

The Implement<C>() method supports two fluent modifiers. The AsSingleInstance() modifier tells the container to create only one instance of the implementing class and pass it out for all requests. For example Container.Implement<IFoo>().Using<Foo>().AsSingleInstance() directs the container to always return the same instance of Foo.

If code attempts to register more than one implementation for a specified interface, the container honors the first registration and ignores all additional implementation instructions for that interface. The WithOverwrite() modifier is an explicit means to indicate that the new implementation takes priority.