I recently decided to switch my IoC container from Ninject to Unity for my ASP.NET Web API Web Application because the Ninject IoC container has poor support for Web API and has not been updated/refreshed in several years.
It is as simple as that!
So, naturally, when I began switching my code over from Ninject over to Unity, one of the questions that immediately came up was how to use constructor parameters for my types in Unity?
Well, after doing some quick searching and experimentation, I came up with this solution:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Set up the database connection string | |
var conString = ConfigurationManager.ConnectionStrings["MyDbContext"].ConnectionString; | |
//Add DbContext bindings | |
container.RegisterType<MyDbContext>(new InjectionConstructor(conString)); |
No comments:
Post a Comment