Exemplo 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);
            }
        }
Exemplo n.º 2
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();
        }