Infuse is a simple IoC container made for educational purposes!
This purpose of this project is to serve as an educational greed for one to understand the internals of how IoC containers might work.
The implementation is very general and should not be used in actual production apps. It does not mimic the likes of better containers
out there ([in no particular order] Ninject, Autofac etc.) as it would defeat the very purpose this was built for - 'possible explanation of how IoC are build and function'
There are few features that the Infuse container provides:
- Support for two lifecycle types for object registration
LifecycleType.Transient
- A new instance of the object is returned for every resolveLifecycleType.Singleton
- A same instance of the object is returned for every subsequent resolves- Register Types. Multiple ways to do so -
container.Register<TInterface,TConcrete>()
. The default Lifecycle of the objects registered this way isLifecycle.Transient
container.Register<TInterface,TConcrete>(LifecycleType type)
container.RegisterSingleton<TInterface,TConcrete>()
. An Extension methodcontainer.RegisterTransient<TInterface,TConcrete>()
. An Extension method- Registration takes care of notifying if an
TInterface
is already registered in the container - Resolve Types. Multiple ways to do so -
container.Resolve<TInterface>()
container.Resolve(System.Type type)
wheretype
istypeof(TInterface)
- Resolution takes care of following things
- Resolve Singleton from the Singleton store
- Resolving inter-dependency scenarios where DI applies. E.g.:
Controller
is dependent onRepository
. It does so by supporting Constructor Injection at the moment - Informative error resolution in case resolution is attempted to be done for an unregistered type
- xUnit Test Coverage
There are two main folders in the solution -
- src
This folder contains the IoC library project - Infuse: This is the main IoC container project. It's a class library project with dependenct on .NET Standard
- Infuse.Attempt0: This is another IoC container project that was started with initially but ran into snags with design and tests thereon. It's a class library project with dependenct on .NET Standard. It's there in repo because I intend to fix this someday and can be ignored
- test
This folder contains two test projects - Infuse.Test: This is the main IoC container test project. It's a xUnit test project and contains test files for both the IoC container projects
- MvcMovieSampleApp: This is a ASP.NET MVC Sample application project that attempts to show the Infuse IoC in action
- Add sample usage for a ASP.NET Core Web project
- Introduce new options for
LifecycleType
- Support non-public constructors for type resolution
- Explore possibility of other DI injection kinds e.g.: Setter injection
- Publish Infuse to the Nuget for package management
- Explore the possibility to refactor the code to use a version of Infuse library to achieve DI for Infuse
- Create easy to use extensions for using Infuse with different project types. This will be similar to what other container libraries do
- Add API documentation