static void EnsureDefaults(SimpleDependencyResolver dependencyResolver, SmtpAgentSettings settings) { if (!dependencyResolver.IsRegistered <ILogFactory>()) { dependencyResolver.Register <ILogFactory>(new NLogFactory(settings.LogSettings)); } if (!dependencyResolver.IsRegistered <IAuditor>()) { dependencyResolver.Register <IAuditor>(new EventLogAuditor()); } }
private static void InitializeContainer(SmtpAgentSettings settings) { lock (m_initSync) { if (!m_initialized) { SimpleDependencyResolver dependencyResolver = new SimpleDependencyResolver(); if (settings.HasContainer && settings.Container.HasComponents) { try { dependencyResolver.Register(settings.Container); } catch (Exception ex) { LogError(settings, ex); } } EnsureDefaults(dependencyResolver, settings); IoC.Initialize(dependencyResolver); m_initialized = true; } } }
static void EnsureDefaults(SimpleDependencyResolver dependencyResolver, SmtpAgentSettings settings) { if (!dependencyResolver.IsRegistered <ILogFactory>()) { dependencyResolver.Register <ILogFactory>(new NLogFactory(settings.LogSettings)); } if (!dependencyResolver.IsRegistered <IAuditor <IBuildAuditLogMessage> >() && !dependencyResolver.IsRegistered <IAuditor>()) { dependencyResolver.Register <IAuditor <IBuildAuditLogMessage> >(new SmtpAgentEventLogAuditor(new EventLogAuditor())); } if (dependencyResolver.IsRegistered <IAuditor>()) { // // wrap legacy IAuditor // dependencyResolver.Register <IAuditor <IBuildAuditLogMessage> >(new SmtpAgentEventLogAuditor(dependencyResolver.Resolve <IAuditor>())); } }
public void RegisterMultipleComponentsWithSameServiceType() { var container = new SimpleDependencyResolver().RegisterFromConfig(); container.Register <IFoo>(new Foo2()); var foo = container.Resolve <IFoo>(); Assert.IsType <Foo2>(foo); var fooList = container.ResolveAll <IFoo>(); Assert.IsType <List <IFoo> >(fooList); }
private static void InitializeContainer(SmtpAgentSettings settings) { lock (m_initSync) { if (!m_initialized) { SimpleDependencyResolver dependencyResolver = new SimpleDependencyResolver(); if (settings.HasContainer && settings.Container.HasComponents) { try { dependencyResolver.Register(settings.Container); } catch(Exception ex) { LogError(settings, ex); } } EnsureDefaults(dependencyResolver, settings); IoC.Initialize(dependencyResolver); m_initialized = true; } } }
static void EnsureDefaults(SimpleDependencyResolver dependencyResolver, SmtpAgentSettings settings) { if (!dependencyResolver.IsRegistered<ILogFactory>()) { dependencyResolver.Register<ILogFactory>(new NLogFactory(settings.LogSettings)); } if (!dependencyResolver.IsRegistered<IAuditor>()) { dependencyResolver.Register<IAuditor>(new EventLogAuditor()); } }
public void RegisterMultipleComponentsWithSameServiceType() { var container = new SimpleDependencyResolver().RegisterFromConfig(); container.Register<IFoo>(new Foo2()); var foo = container.Resolve<IFoo>(); Assert.IsType<Foo2>(foo); var fooList = container.ResolveAll<IFoo>(); Assert.IsType<List<IFoo>>(fooList); }
static void EnsureDefaults(SimpleDependencyResolver dependencyResolver, SmtpAgentSettings settings) { if (!dependencyResolver.IsRegistered<ILogFactory>()) { dependencyResolver.Register<ILogFactory>(new NLogFactory(settings.LogSettings)); } if (!dependencyResolver.IsRegistered<IAuditor<IBuildAuditLogMessage>>() && !dependencyResolver.IsRegistered<IAuditor>()) { dependencyResolver.Register<IAuditor<IBuildAuditLogMessage>>(new SmtpAgentEventLogAuditor(new EventLogAuditor())); } if (dependencyResolver.IsRegistered<IAuditor>()) { // // wrap legacy IAuditor // dependencyResolver.Register<IAuditor<IBuildAuditLogMessage>>(new SmtpAgentEventLogAuditor(dependencyResolver.Resolve<IAuditor>())); } }