Пример #1
0
            public void RunOnceBeforeAny()
            {
                // Initialize configuration providers to use the actual web.config file, linked into this project from main web project
                var configSectionProvider = new ExternalConfigFileSectionProvider("web.config");
                var configValueProvider = new ExternalConfigFileConfigValueProvider(configSectionProvider);

                var containerFactory = new InversionOfControlContainerFactory(
                    configSectionProvider,
                    configValueProvider);

                // Get the container
                Container = containerFactory.CreateContainer(c =>
                    {
                        // Add the array resolver for resolving arrays of services automatically
                        c.Kernel.Resolver.AddSubResolver(new ArrayResolver(c.Kernel));

                        // Make sure for this testing that we're using the config value provider initialized above
                        c.Register(Component.For<IConfigSectionProvider>().Instance(configSectionProvider));
                        c.Register(Component.For<IConfigValueProvider>().Instance(configValueProvider));

                        // Initialize the service locator with the container 
                        // (enabling installers to access container through IoC during registration process)
                        IoC.Initialize(c);
                    });
                // Register the wrapped service locator singleton instance
                Container = Container.Register(
                    Component.For<IServiceLocator>()
                        .Instance(IoC.WrappedServiceLocator));
            }
Пример #2
0
        private static void InitializeInversionOfControl()
        {
            // Initialize the IoC container using the main Web.config file
            var containerFactory = new InversionOfControlContainerFactory(
                new ExternalConfigFileSectionProvider("web.config"),    // Use main web.config
                new NameValueCollectionConfigValueProvider());          // Use "empty" appSettings

            var container = containerFactory.CreateContainer(
                // Initialize the service locator with the container 
                // (enabling installers to access container through IoC during registration process)
                IoC.Initialize);

            // Register the wrapped service locator singleton instance
            container.Register(
                Component.For<IServiceLocator>()
                    .Instance(IoC.WrappedServiceLocator));
        }