static void Main(string[] args) { var ext = new NLogExtension() { GetName = (t, n) => t.FullName }; _container = new UnityContainer(); _container.AddExtension(ext). RegisterType <ITestComponent, Baranina>("baranina"). RegisterType <ITestComponent, Cielecina>("cielecina"). RegisterType <ITestConstructorInjection, TestConstructorInjection>(); var _instance = _container.Resolve <Class1>(); _instance.GetName += GetName; _instance.GetName += GetName2; _instance.GetName += GetName3; _instance.GetName += GetName4; _instance.TestLogging(); ITestComponent baranina = _container.Resolve <Baranina>(); baranina.GetName(); var bar2 = _container.Resolve <ITestComponent>("baranina"); ITestComponent cielecina = _container.Resolve <Cielecina>(); cielecina.GetName(); Console.ReadLine(); }
/// <summary> /// Registers the type mappings with the Unity container. /// </summary> /// <param name="container">The unity container to configure.</param> /// <remarks> /// There is no need to register concrete types such as controllers or /// API controllers (unless you want to change the defaults), as Unity /// allows resolving a concrete type even if it was not previously /// registered. /// </remarks> public static void RegisterTypes(IUnityContainer container) { // NOTE: To load from web.config uncomment the line below. // Make sure to add a Unity.Configuration to the using statements. // container.LoadConfiguration(); // TODO: Register your type's mappings here. // container.RegisterType<IProductRepository, ProductRepository>(); // Binding ILogger to NLog var ext = new NLogExtension { GetName = (t, n) => t.Name }; container.AddExtension(ext); // Binding the repository container.RegisterType <IRepo, Repo>(); }