Hi Folks! In this post I would like to share my learnings on Unity Container which is one the IoC Container Frameworks. We will see how to configure Unity container both in older version and newer version. Why both? Because there is a slight change in configuration. So, let’s start.
Consider below are the projects in a Visual Studio solution.
Here each of the projects references interface project.(This is just a demo example to understand dependency injection using configuration)
Unity v5.2.1 installed in Entities class library.
To avoid hard reference to OracleDataProvider and SQLDataProvider in DIFrameworkDemo, I have used xcopy in Post-build event command line of the DataProvider class libraries.
Note: Make sure you update your config if you upgrade to 5.2.1 or newer version otherwise you will get below error.
An unhandled exception of type ‘System.Configuration.ConfigurationErrorsException’ occurred in System.Configuration.dll
Additional information: An error occurred creating the configuration section handler for unity: Could not load file or assembly ‘Microsoft.Practices.Unity.Configuration’ or one of its dependencies. The system cannot find the file specified.
This happens because Microsoft.Practices.Unity.Configuration.UnityConfigurationSection class is moved to Unity.Configuration.dll.
Hope this helps.