Unity DI config implementation question
-
I am implementing Unity in a business app for the first time. Here is some sample code to implement logging DI with Unity:
UnityContainer uc = new UnityContainer(); uc.RegisterType<ILogger, FileLogger>(); ILogger logger = uc.Resolve<ILogger>(); logger.Write();
One way to implement this in an app would be to put this code in an AppConfig.cs class and implement GetLogger as a singleton. What's your preferred way to implement Unity in this scenario? -
I am implementing Unity in a business app for the first time. Here is some sample code to implement logging DI with Unity:
UnityContainer uc = new UnityContainer(); uc.RegisterType<ILogger, FileLogger>(); ILogger logger = uc.Resolve<ILogger>(); logger.Write();
One way to implement this in an app would be to put this code in an AppConfig.cs class and implement GetLogger as a singleton. What's your preferred way to implement Unity in this scenario? -
I think Singleton is best way of implementing. Why would you choose other way? any specific requirements? :)
Ok - so to implement this as a singleton how would you envision the solution structure? For example, would you see a singleton class in its own class library with a namespace like: "MyCompany.MyDivision.MyApp.DI"? With the singleton class named something like "DIManager"? Then I suppose that every library that needed the DI info would need to add a reference to the custom DI class library? Is this correct?