예제 #1
0
 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());
     }
 }
예제 #2
0
        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;
                }
            }
        }
예제 #3
0
 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>()));
     }
 }
예제 #4
0
        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);
        }
예제 #5
0
 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;
         }
     }
 }
예제 #6
0
 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());
     }
 }
예제 #7
0
        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);
        }
예제 #8
0
 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>()));
     }
 }