Here is some simple code that configures a UnityContainer, registers a few different types of loggers and then gets a handle to one of the logger types:
var logger = container.Resolve<ILogger>("FileLogger");
I think this standalone code is fairly straightforward. However, I am curious about the best way to access this code in an application.
Seems like it might be easiest to include this config code in an AppConfig.cs class and then reference the AppConfig.cs class as a Singleton throughout the application.
I need to implement Unity for the first time in a business app. How do you normally choose to implement Unity in your business apps?
dotnetterAMG...
Member
234 Points
510 Posts
question about instantiating unity
Feb 06, 2011 04:22 AM|LINK
Here is some simple code that configures a UnityContainer, registers a few different types of loggers and then gets a handle to one of the logger types:
IUnityContainer container = new UnityContainer();
container.RegisterType<ILogger, FileLogger>("FileLogger");
container.RegisterType<ILogger, DatabaseLogger>("DBLogger");
var logger = container.Resolve<ILogger>("FileLogger");
I think this standalone code is fairly straightforward. However, I am curious about the best way to access this code in an application.
Seems like it might be easiest to include this config code in an AppConfig.cs class and then reference the AppConfig.cs class as a Singleton throughout the application.
I need to implement Unity for the first time in a business app. How do you normally choose to implement Unity in your business apps?