Пример #1
0
		public void SetUp()
		{
			assemblyCache = new TypeCache(new N2.Persistence.BasicTemporaryFileHelper(new ThreadContext()));
			var config = new N2.Configuration.EngineSection();
			config.Assemblies.SkipLoadingPattern = "nothing";
			config.Assemblies.Remove(new N2.Configuration.AssemblyElement("N2.Management"));
			config.Assemblies.EnableTypeCache = false;
			typeFinder = new WebAppTypeFinder(assemblyCache, config);
		}
        public virtual void Configure(IEngine engine, EventBroker broker, ConfigurationManagerWrapper configuration)
        {
            engine.Container.AddComponentInstance("n2.configuration", typeof(ConfigurationManagerWrapper), configuration);
            engine.Container.AddComponentInstance("n2.engine", typeof(IEngine), engine);
            engine.Container.AddComponentInstance("n2.container", typeof(IServiceContainer), engine.Container);
            engine.Container.AddComponentInstance("n2.containerConfigurer", typeof(ContainerConfigurer), this);

            AddComponentInstance(engine.Container, configuration.GetConnectionStringsSection());
            AddComponentInstance(engine.Container, configuration.Sections.Engine);
            RegisterConfiguredComponents(engine.Container, configuration.Sections.Engine);
            AddComponentInstance(engine.Container, configuration.Sections.Web);
            InitializeEnvironment(engine.Container, configuration.Sections);
            AddComponentInstance(engine.Container, configuration.Sections.Database);
            AddComponentInstance(engine.Container, configuration.Sections.Management);
            AddComponentInstance(engine.Container, broker);

            var skipTypes = configuration.Sections.Engine.Components.GetConfiguredServiceTypes();

#if DEBUG_2
            var watf = new WebAppTypeFinder(new TypeCache(new BasicTemporaryFileHelper(null)), configuration.Sections.Engine);
            engine.Container.AddComponentInstance(watf.GetType().FullName, typeof(ITypeFinder), watf);
            var registrator = new ServiceRegistrator(watf, engine.Container);
#else
            AddComponentUnlessConfigured(engine.Container, typeof(BasicTemporaryFileHelper), typeof(BasicTemporaryFileHelper), skipTypes);
            AddComponentUnlessConfigured(engine.Container, typeof(TypeCache), typeof(TypeCache), skipTypes);
            AddComponentUnlessConfigured(engine.Container, typeof(ITypeFinder), typeof(WebAppTypeFinder), skipTypes);
            AddComponentUnlessConfigured(engine.Container, typeof(ServiceRegistrator), typeof(ServiceRegistrator), skipTypes);
            var registrator = engine.Container.Resolve <ServiceRegistrator>();
#endif
            var services          = registrator.FindServices();
            var configurationKeys = configuration.GetComponentConfigurationKeys();
            services = registrator.FilterServices(services, configurationKeys);
            services = registrator.FilterServices(services, skipTypes);
            registrator.RegisterServices(services);

            // workaround for problem with open generic binding for IRepository<> - requires that [Service] attributes be removed
            var cir = engine.Container.Resolve <IContentItemRepository>();
            // register the signleton the hard way
            engine.Container.AddComponentInstance("n2.IRepository.ContentItem", typeof(IRepository <ContentItem>), cir);
#if DEBUG_2
            // double check container sanity
            var test = engine.Container.Resolve <IRepository <ContentItem> >();
            Logger.Debug(cir.GetType().FullName);
            Logger.Debug(test.GetType().FullName);
            if (!cir.Equals(test))
            {
                throw new Exception("inconsistent repositories");
            }
#endif
            InitializeUrlParser(engine.Container);
        }
Пример #3
0
        public virtual void Configure(IEngine engine, EventBroker broker, ConfigurationManagerWrapper configuration)
        {
            engine.Container.AddComponentInstance("n2.configuration", typeof(ConfigurationManagerWrapper), configuration);
            engine.Container.AddComponentInstance("n2.engine", typeof(IEngine), engine);
            engine.Container.AddComponentInstance("n2.container", typeof(IServiceContainer), engine.Container);
            engine.Container.AddComponentInstance("n2.containerConfigurer", typeof(ContainerConfigurer), this);

            AddComponentInstance(engine.Container, configuration.GetConnectionStringsSection());
            AddComponentInstance(engine.Container, configuration.Sections.Engine);
            RegisterConfiguredComponents(engine.Container, configuration.Sections.Engine);
            AddComponentInstance(engine.Container, configuration.Sections.Web);
            InitializeEnvironment(engine.Container, configuration.Sections);
            AddComponentInstance(engine.Container, configuration.Sections.Database);
            AddComponentInstance(engine.Container, configuration.Sections.Management);
            AddComponentInstance(engine.Container, broker);

            var skipTypes = configuration.Sections.Engine.Components.GetConfiguredServiceTypes();
#if DEBUG_2
            var watf = new WebAppTypeFinder(new TypeCache(new BasicTemporaryFileHelper(null)), configuration.Sections.Engine);
            engine.Container.AddComponentInstance(watf.GetType().FullName, typeof(ITypeFinder), watf);
            var registrator = new ServiceRegistrator(watf, engine.Container);

#else
            AddComponentUnlessConfigured(engine.Container, typeof(BasicTemporaryFileHelper), typeof(BasicTemporaryFileHelper), skipTypes);
            AddComponentUnlessConfigured(engine.Container, typeof(TypeCache), typeof(TypeCache), skipTypes);
            AddComponentUnlessConfigured(engine.Container, typeof(ITypeFinder), typeof(WebAppTypeFinder), skipTypes);
            AddComponentUnlessConfigured(engine.Container, typeof(ServiceRegistrator), typeof(ServiceRegistrator), skipTypes);
            var registrator = engine.Container.Resolve<ServiceRegistrator>();
#endif
            var services = registrator.FindServices();
            var configurationKeys = configuration.GetComponentConfigurationKeys();
            services = registrator.FilterServices(services, configurationKeys);
            services = registrator.FilterServices(services, skipTypes);
            registrator.RegisterServices(services);

            // workaround for problem with open generic binding for IRepository<> - requires that [Service] attributes be removed
            var cir = engine.Container.Resolve<IContentItemRepository>();
            // register the signleton the hard way
            engine.Container.AddComponentInstance("n2.IRepository.ContentItem", typeof(IRepository<ContentItem>), cir);
#if DEBUG_2
            // double check container sanity
            var test = engine.Container.Resolve<IRepository<ContentItem>>();
            Logger.Debug(cir.GetType().FullName);
            Logger.Debug(test.GetType().FullName);
            if (!cir.Equals(test))
                throw new Exception("inconsistent repositories");
#endif
            InitializeUrlParser(engine.Container);
        }