Пример #1
0
        public void TransformerRegistration_Success()
        {
            var transformers = new List <TransformerConfiguration>();

            transformers.Add(CreateTransformerConfig("1", CreateMapperConfig("2", "1"), "3"));

            ComponentRegistration.Reset();
            // the collector needs to be resgistered since it is injected
            ComponentRegistration.RegisterComponent <ICollector>(ConfigurationTests.TYPE_COLLECTOR);
            ComponentRegistration.RegisterComponents(transformers);
            ComponentRegistration.RegisterTypesFromAssembly(new ThirdPartyAutofacConfiguration()
            {
                AssemblyName = COLLECTOR_SDK_ASSEMBLY,
                Type         = "LoggerFacade"
            });
            ComponentRegistration.RegisterModulesFromAssembly(new ThirdPartyAutofacConfiguration()
            {
                AssemblyName = NLOG_EXTRAS_ASSEMBLY,
                RegisterAll  = true
            });
            ComponentRegistration.Build();
            var reader = ComponentRegistration.CreateInstance <ITransformer>(ConfigurationTests.TYPE_TRANSFORMER);

            reader.Should().NotBeNull();
        }
Пример #2
0
        public void SingletonRegistration_Fails_Without_Singleton_Flag()
        {
            var readers = new List <ReaderConfiguration>();

            readers.Add(CreateReaderWithSingletonDependencyConfig("1", "2"));

            ComponentRegistration.Reset();
            // the collector needs to be registered since it is injected
            ComponentRegistration.RegisterComponent <ICollector>(ConfigurationTests.TYPE_COLLECTOR);
            ComponentRegistration.RegisterComponents(readers);
            ComponentRegistration.RegisterTypesFromAssembly(new ThirdPartyAutofacConfiguration()
            {
                AssemblyName = COLLECTOR_SDK_ASSEMBLY,
                Type         = "LoggerFacade"
            });
            ComponentRegistration.RegisterModulesFromAssembly(new ThirdPartyAutofacConfiguration()
            {
                AssemblyName = NLOG_EXTRAS_ASSEMBLY,
                RegisterAll  = true
            });
            ComponentRegistration.Build();

            IReader reader = null;

            Assert.ThrowsException <DependencyResolutionException>(() => reader = ComponentRegistration.CreateInstance <IReader>(ConfigurationTests.TYPE_READER_WITH_SINGLETON_DEPENDENCY));
            reader.Should().BeNull();
        }
Пример #3
0
        public void SingletonRegistration_Build_Success()
        {
            var readers = new List <ReaderConfiguration>();

            readers.Add(CreateReaderWithSingletonDependencyConfig("1", "2"));

            ComponentRegistration.Reset();
            // the collector needs to be registered since it is injected
            ComponentRegistration.RegisterComponent <ICollector>(ConfigurationTests.TYPE_COLLECTOR);
            ComponentRegistration.RegisterComponents(readers);
            ComponentRegistration.RegisterTypesFromAssembly(new ThirdPartyAutofacConfiguration()
            {
                AssemblyName = COLLECTOR_SDK_ASSEMBLY,
                Type         = "LoggerFacade"
            });
            ComponentRegistration.RegisterTypesFromAssembly(new ThirdPartyAutofacConfiguration()
            {
                AssemblyName = typeof(MockDisposableSingleton).Assembly.GetName().Name,
                Type         = nameof(MockDisposableSingleton),
                Singleton    = true
            });
            ComponentRegistration.RegisterModulesFromAssembly(new ThirdPartyAutofacConfiguration()
            {
                AssemblyName = NLOG_EXTRAS_ASSEMBLY,
                RegisterAll  = true
            });
            ComponentRegistration.Build();
            var reader = ComponentRegistration.CreateInstance <IReader>(ConfigurationTests.TYPE_READER_WITH_SINGLETON_DEPENDENCY);

            reader.Should().NotBeNull();
        }
Пример #4
0
        public void ReaderRegistration_Success()
        {
            var readers = new List <ReaderConfiguration>();

            readers.Add(CreateReaderConfig("1", "2"));

            ComponentRegistration.Reset();
            // the collector needs to be resgistered since it is injected
            ComponentRegistration.RegisterComponent <ICollector>(ConfigurationTests.TYPE_COLLECTOR);
            ComponentRegistration.RegisterComponents(readers);
            ComponentRegistration.RegisterTypesFromAssembly(new ThirdPartyAutofacConfiguration()
            {
                AssemblyName = "Collector.SDK",
                Type         = "LoggerFacade"
            });
            ComponentRegistration.RegisterModulesFromAssembly(new ThirdPartyAutofacConfiguration()
            {
                AssemblyName = "Autofac.Extras.NLog",
                RegisterAll  = true
            });
            ComponentRegistration.Build();
            var reader = ComponentRegistration.CreateInstance <IReader>(ConfigurationTests.TYPE_READER);

            reader.Should().NotBeNull();
        }
        protected void Application_Start()
        {
            ComponentRegistration.RegisterComponents();
            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
Пример #6
0
        /// <summary>
        /// Create a Collector, this involved creating all the layers - Readers, Transformers and Publishers.
        /// </summary>
        /// <param name="collectorConfig">The configuration that defines all the layers.</param>
        /// <param name="mapperConfigs">The mappers to use by transformers.</param>
        /// <returns></returns>
        public static ICollector CreateCollector(CollectorConfiguration collectorConfig)
        {
            ComponentRegistration.RegisterComponents(collectorConfig);
            ComponentRegistration.Build();

            var collector = ComponentRegistration.CreateInstance <ICollector>(collectorConfig.Type);

            collector.Configure(collectorConfig);
            return(collector);
        }
Пример #7
0
        /// <summary>
        /// Create an array of collectors
        /// </summary>
        /// <param name="collectorConfigs">An array of collector configurations</param>
        /// <returns>a list of collectors</returns>
        public static List <ICollector> CreateCollectors(CollectorConfiguration[] collectorConfigs)
        {
            var result = new List <ICollector>();

            foreach (var config in collectorConfigs)
            {
                ComponentRegistration.RegisterComponents(config);
            }
            ComponentRegistration.Build();
            foreach (var config in collectorConfigs)
            {
                var collector = ComponentRegistration.CreateInstance <ICollector>(config.Type);
                collector.Configure(config);
                result.Add(collector);
            }
            return(result);
        }
Пример #8
0
        public void CollectorRegistration_Success()
        {
            ComponentRegistration.Reset();
            ComponentRegistration.RegisterComponents(CreateCollectorConfig("1"));
            ComponentRegistration.RegisterTypesFromAssembly(new ThirdPartyAutofacConfiguration()
            {
                AssemblyName = COLLECTOR_SDK_ASSEMBLY,
                Type         = "LoggerFacade"
            });
            ComponentRegistration.RegisterModulesFromAssembly(new ThirdPartyAutofacConfiguration()
            {
                AssemblyName = NLOG_EXTRAS_ASSEMBLY,
                RegisterAll  = true
            });
            ComponentRegistration.Build();
            var collector = ComponentRegistration.CreateInstance <ICollector>(ConfigurationTests.TYPE_COLLECTOR);

            collector.Should().NotBeNull();
        }