Ejemplo n.º 1
0
        public void Initialize(IModuleInfo moduleInfo)
        {
            if (moduleInfo == null)
            {
                throw new ArgumentNullException(nameof(moduleInfo));
            }

            IModule moduleInstance = null;

            try
            {
                moduleInstance = this.CreateModule(moduleInfo);
                if (moduleInstance != null)
                {
                    var mutableContainer = _containerExtension.GetMutableContainer();
                    mutableContainer.RegisterTypes(builder =>
                    {
                        var registry = new AutofacContainerRegistry(builder, mutableContainer);
                        moduleInstance.RegisterTypes(registry);
                        registry.FinalizeRegistry();
                    });

                    moduleInstance.OnInitialized(_containerExtension);
                }
            }
            catch (Exception ex)
            {
                this.HandleModuleInitializationError(
                    moduleInfo,
                    moduleInstance != null ? moduleInstance.GetType().Assembly.FullName : null,
                    ex);
            }
        }
Ejemplo n.º 2
0
        public void AutofacContainerRegistryShouldReturnFalseForIsRegisteredDuringRegistration()
        {
            var registry = new AutofacContainerRegistry(new ContainerBuilder());

            registry.Register <IService, Service>();
            registry.IsRegistered <IService>().Should().BeFalse();
        }
Ejemplo n.º 3
0
        public void AutofacContainerRegistryShouldReturnTrueForIsRegisteredOnExistingRegistrations()
        {
            var builder = new ContainerBuilder();

            builder.RegisterType <Service>().As <IService>();
            var container = new MutableContainer(builder);

            var registry = new AutofacContainerRegistry(new ContainerBuilder(), container);

            registry.IsRegistered <IService>().Should().BeTrue();
        }
Ejemplo n.º 4
0
        public void AutofacContainerRegistryShouldReturnTrueForIsRegisteredAfterRegistration()
        {
            var container = new MutableContainer(new ContainerBuilder());

            AutofacContainerRegistry registry = null;

            container.RegisterTypes(b =>
            {
                registry = new AutofacContainerRegistry(b, container);
                registry.Register <IService, Service>();
                registry.FinalizeRegistry();
            });
            registry.IsRegistered <IService>().Should().BeTrue();
        }