Example #1
0
        protected void RegisterSessionStore()
        {
            String isWeb       = FacilityConfig.Attributes["isWeb"];
            String customStore = FacilityConfig.Attributes["customStore"];

            // Default implementation
            Type sessionStoreType = typeof(CallContextSessionStore);

            if ("true".Equals(isWeb))
            {
                sessionStoreType = typeof(WebSessionStore);
            }

            if (customStore != null)
            {
                ITypeConverter converter = (ITypeConverter)
                                           Kernel.GetSubSystem(SubSystemConstants.ConversionManagerKey);

                sessionStoreType = (Type)
                                   converter.PerformConversion(customStore, typeof(Type));

                if (!typeof(ISessionStore).IsAssignableFrom(sessionStoreType))
                {
                    throw new ConfigurationErrorsException("The specified customStore does " +
                                                           "not implement the interface ISessionStore. Type " + customStore);
                }
            }

            Kernel.AddComponent("nhfacility.sessionstore",
                                typeof(ISessionStore), sessionStoreType);
        }
        public void BlogPlainFields()
        {
            Kernel.AddComponent("plainfields", typeof(IPlainFieldInferenceService), typeof(PlainFieldInferenceService));
            Kernel.AddComponent("nameService", typeof(INamingService), typeof(NamingService));
            Kernel.AddComponent("typeinf", typeof(ITypeInferenceService), typeof(TypeInferenceService));

            IPlainFieldInferenceService plainService = Kernel[typeof(IPlainFieldInferenceService)] as IPlainFieldInferenceService;

            TableDefinition table = new TableDefinition("blogs", new DatabaseDefinition("alias"));

            table.AddColumn(new ColumnDefinition("id", true, false, true, false, OleDbType.Integer));
            table.AddColumn(new ColumnDefinition("name", false, false, false, false, OleDbType.VarChar));
            table.AddColumn(new ColumnDefinition("authorid", false, true, false, false, OleDbType.VarChar));

            ActiveRecordPropertyDescriptor[] descs = plainService.InferProperties(table);

            Assert.IsNotNull(descs);
            Assert.AreEqual(2, descs.Length);

            ActiveRecordPropertyDescriptor desc1 = descs[0];
            ActiveRecordPropertyDescriptor desc2 = descs[1];

            Assert.AreEqual("id", desc1.ColumnName);
            Assert.AreEqual("Integer", desc1.ColumnTypeName);
            Assert.AreEqual("Id", desc1.PropertyName);
            Assert.AreEqual(typeof(int), desc1.PropertyType);

            Assert.AreEqual("name", desc2.ColumnName);
            Assert.AreEqual("VarChar", desc2.ColumnTypeName);
            Assert.AreEqual("Name", desc2.PropertyName);
            Assert.AreEqual(typeof(String), desc2.PropertyType);
        }
 private void InitKernel()
 {
     Kernel.AddComponent("relationsService", typeof(IRelationshipInferenceService), typeof(RelationshipInferenceService));
     Kernel.AddComponent("relationBuilder", typeof(IRelationshipBuilder), typeof(RelationshipBuilder));
     Kernel.AddComponent("nameService", typeof(INamingService), typeof(NamingService));
     Kernel.AddComponent("typeinf", typeof(ITypeInferenceService), typeof(TypeInferenceService));
 }
        protected override void Init()
        {
            if (FacilityConfig == null)
            {
                throw new System.Configuration.ConfigurationException(
                          "The NHibernateFacility requires an external configuration");
            }

            IConfiguration factoriesConfig = FacilityConfig.Children["factory"];

            if (factoriesConfig == null)
            {
                throw new System.Configuration.ConfigurationException(
                          "You need to configure at least one factory to use the NHibernateFacility");
            }

            Kernel.ComponentModelBuilder.AddContributor(new AutomaticSessionInspector());

            Kernel.AddComponent("nhibernate.session.interceptor", typeof(AutomaticSessionInterceptor));

            Kernel.AddComponent("nhibernate.transaction.manager", typeof(ITransactionManager), typeof(NHibernateTransactionManager));

            foreach (IConfiguration factoryConfig in FacilityConfig.Children)
            {
                if (!"factory".Equals(factoryConfig.Name))
                {
                    throw new System.Configuration.ConfigurationException("Unexpected node " + factoryConfig.Name);
                }

                ConfigureFactories(factoryConfig);
            }
        }
Example #5
0
        protected override void Init()
        {
            if (FacilityConfig == null)
            {
                throw new ConfigurationException("The IBatisNetFacility requires an external configuration");
            }

            Kernel.ComponentModelBuilder.AddContributor(new AutomaticSessionInspector());
            Kernel.AddComponent("IBatis.session.interceptor", typeof(AutomaticSessionInterceptor));
            Kernel.AddComponent("IBatis.transaction.manager", typeof(ITransactionManager), typeof(DataMapperTransactionManager));

            int factories = 0;

            foreach (IConfiguration factoryConfig in FacilityConfig.Children)
            {
                if (factoryConfig.Name == "sqlMap")
                {
                    ConfigureFactory(factoryConfig);
                    factories++;
                }
            }

            if (factories == 0)
            {
                throw new ConfigurationException("You need to configure at least one sqlMap for IBatisNetFacility");
            }
        }
 protected override void Init()
 {
     Kernel.AddComponent("docking.layoutRegistry", typeof(IDockingLayoutRegistry),
                         typeof(DockingLayoutRegistry));
     Kernel.AddComponent("docking.controller", typeof(IDockingController), typeof(DockingController));
     Kernel.ComponentRegistered += Kernel_ComponentRegistered;
 }
Example #7
0
        private void AddComponents(IConfiguration config)
        {
            String assemblyName = config.Attributes["name"];

            if (assemblyName == null || assemblyName.Length == 0)
            {
                throw new ConfigurationException("The assemblyBatch node must have a 'name' " +
                                                 " attribute with the name of the assembly");
            }

            ComponentScanner scanner = new ComponentScanner(assemblyName);

            ConfigureScanner(config, scanner);

            ComponentDefinition[] definitions = scanner.Process();

            foreach (ComponentDefinition definition in definitions)
            {
                if (definition.ServiceType == null)
                {
                    Kernel.AddComponent(definition.Key, definition.ClassType);
                }
                else
                {
                    Kernel.AddComponent(definition.Key, definition.ServiceType, definition.ClassType);
                }
            }
        }
Example #8
0
        public void Connect(string id, Type classType, Type serviceType, ComponentLifestyle lifestyle)
        {
            Hashtable extendingProperties = new Hashtable();

            extendingProperties[typeof(ComponentLifestyle)] = lifestyle;

            switch (lifestyle)
            {
            case ComponentLifestyle.Singleton:
                Kernel.AddComponentWithExtendedProperties(id, serviceType, classType, extendingProperties);
                break;

            case ComponentLifestyle.Transient:
                Kernel.AddComponentWithExtendedProperties(id, serviceType, classType, extendingProperties);
                break;

            case ComponentLifestyle.DependencyInjectionOnly:
                Kernel.AddComponentWithExtendedProperties(id, serviceType, classType, extendingProperties);
                break;

            case ComponentLifestyle.Undefined:
                Kernel.AddComponent(id, serviceType, classType);
                break;

            default:
                throw new ArgumentException("ComponentLifestyle 参数无效: " + lifestyle);
            }
        }
Example #9
0
        /// <summary>
        /// 初始化方法
        /// </summary>
        protected override void Init()
        {
            Kernel.AddComponent("SystemService", typeof(ISystemService), typeof(SystemService));
            SystemComponentInspector inspector = new SystemComponentInspector(Kernel[typeof(ISystemService)] as ISystemService);

            Kernel.ComponentModelBuilder.AddContributor(inspector);
        }
        /// <summary>
        ///
        /// </summary>
        protected override void Init()
        {
            if (FacilityConfig == null)
            {
                throw new ConfigurationException(
                          "The MVCFacility requires an 'assembyView' child tag.");
            }

            IConfiguration factoriesConfig = FacilityConfig.Children["assembyView"];

            if (factoriesConfig != null &&
                factoriesConfig.Value != null && factoriesConfig.Value != string.Empty)
            {
                _assembly = Assembly.Load(factoriesConfig.Value);
            }

            // Added TypedFactory to have a IState factory
            TypedFactoryFacility facility = new TypedFactoryFacility();

            Kernel.AddFacility("typedfactory", facility);
            facility.AddTypedFactoryEntry(new FactoryEntry("stateFactory", typeof(IStateFactory), "Create", "Release"));

            // Added a ControlerTree component to track controller by view
            Kernel.AddComponent("mvc.controllerTree", typeof(ControllerTree));
            Kernel.ComponentModelCreated += new ComponentModelDelegate(OnComponentModelCreated);

            Initialize();
        }
Example #11
0
 private void SetUpTransactionManager()
 {
     if (!Kernel.HasComponent(typeof(ITransactionManager)))
     {
         Kernel.AddComponent("ar.transaction.manager",
                             typeof(ITransactionManager), typeof(ActiveRecordTransactionManager));
     }
 }
Example #12
0
 private void InitKernel()
 {
     Kernel.AddComponent("relationsService", typeof(IRelationshipInferenceService), typeof(RelationshipInferenceService));
     Kernel.AddComponent("nameService", typeof(INamingService), typeof(NamingService));
     Kernel.AddComponent("typeinf", typeof(ITypeInferenceService), typeof(TypeInferenceService));
     Kernel.AddComponent("plain", typeof(IPlainFieldInferenceService), typeof(PlainFieldInferenceService));
     Kernel.AddComponent("arbuild", typeof(IActiveRecordDescriptorBuilder), typeof(ActiveRecordDescriptorBuilder));
 }
Example #13
0
 private void SetUpTransactionManager()
 {
     if (!Kernel.HasComponent(typeof(ITransactionManager)))
     {
         Kernel.AddComponent("rhino.transaction.manager",
                             typeof(ITransactionManager), typeof(DefaultTransactionManager));
     }
 }
        protected override void Init()
        {
            Kernel.AddComponent("typed.fac.interceptor", typeof(FactoryInterceptor));

            ITypeConverter converter = (ITypeConverter)
                                       Kernel.GetSubSystem(SubSystemConstants.ConversionManagerKey);

            AddFactories(FacilityConfig, converter);
        }
		public void CorrectInference()
		{
			Kernel.AddComponent( "typeinf", typeof(ITypeInferenceService), typeof(TypeInferenceService) );

			ITypeInferenceService typeInf = Kernel[ typeof(ITypeInferenceService) ] as ITypeInferenceService;

			Assert.AreEqual( typeof(String), typeInf.ConvertOleType( OleDbType.VarChar ) );
			Assert.AreEqual( typeof(int), typeInf.ConvertOleType( OleDbType.Integer ) );
		}
Example #16
0
        protected override void Init()
        {
            SetupConfiguration();
            IConversionManager cm = (IConversionManager)Kernel.GetSubSystem(SubSystemConstants.ConversionManagerKey);

            cm.Add(new RegularExpressionConverter());
            Kernel.AddComponent("policy.intercepter", typeof(AdvisorInterceptor));
            Kernel.ComponentRegistered += new global::Castle.MicroKernel.ComponentDataDelegate(ComponentRegistered);
        }
 private void AddAllComponents()
 {
     foreach (ComponentConfiguration cfg in _componentsByTypeName.Values)
     {
         Type interfaceType      = Type.GetType(cfg.Interface, true, false);
         Type implementationType = Type.GetType(cfg.Implementation, true, false);
         Kernel.AddComponent(cfg.Id, interfaceType, implementationType);
     }
 }
Example #18
0
 protected override void Init()
 {
     Kernel.AddComponent <ProfilingInterceptor>(LifestyleType.Thread);
     Kernel.ComponentModelCreated += model => {
         if (model.Implementation != typeof(ProfilingInterceptor))
         {
             model.Interceptors.AddFirst(InterceptorReference.ForType <ProfilingInterceptor>());
         }
     };
 }
        protected IPool InitPool(int initialSize, int maxSize)
        {
            if (!Kernel.HasComponent(typeof(IPoolFactory)))
            {
                Kernel.AddComponent("castle.internal.poolfactory", typeof(IPoolFactory), typeof(DefaultPoolFactory));
            }

            IPoolFactory factory = Kernel[typeof(IPoolFactory)] as IPoolFactory;

            return(factory.Create(initialSize, maxSize, ComponentActivator));
        }
Example #20
0
        public void InitializeContainer(IApplicationContext context, PredefinedService[] predefinedServices)
        {
            ((DefaultKernel)Kernel).ComponentModelBuilder = new ComponentModelBuilder(Kernel);

            Kernel.ReleasePolicy = new ExplicitReleasePolicy();


            Connect(RuntimeConstants.MiniKernelId, this, typeof(IKernel));

            Connect("kernel", Kernel, typeof(IKernel));
            Connect("windsorContainer", this, typeof(IWindsorContainer));

            //AddCustomComponents(context);
            Kernel.AddComponentInstance(RuntimeConstants.RuntimeConfigurationId, typeof(IApplicationContext), context);


            if (KernelLogger.IsDebugEnabled)
            {
                new KernelLogger(Kernel);
            }

            Kernel.AddComponentInstance(RuntimeConstants.ProductId, typeof(IApplicationContext), context);


            //AddCustomFacilities();
            AddFacility(ComponentIdAwareFacilityId,
                        new TypeAwareFacility(ComponentIdAwareConcern.ComponentIdAwareModelPropertyName, typeof(IComponentIdAware),
                                              ComponentIdAwareConcern.Instance));
            AddFacility(ServiceRunnerFacility.ComponentTypeId, new ServiceRunnerFacility());
            AddFacility(ComponentFacility.ComponentTypeId, new ComponentFacility());


            if (null != context.Arguments)
            {
                Connect(RuntimeConstants.ParsedCommandLineArgumentsId, context.Arguments, typeof(ICommandLineArguments));
            }



            _logger.Debug(" + 开始添加预定义的服务...");

            foreach (PredefinedService svc in predefinedServices)
            {
                Kernel.AddComponent(svc.Id, svc.Service, svc.Implementation);
            }

            _logger.Debug(" > 添加预定义的服务完成.");


            //_initializing = false;
            //_initialized = true;
        }
Example #21
0
        /// <summary>
        /// The custom initialization for the Facility.
        /// </summary>
        /// <remarks>It must be overriden.</remarks>
        protected override void Init()
        {
            strategies = new IInjectedEntityStrategy[]
            {
                new InjectedEntityUsingEagerLoadStrategy(Kernel),
                new InjectedEntityUsingFetchingStrategyStrategy(Kernel),
                new InjectedEntityUsingGetMethodStrategy(Kernel)
            };

            Kernel.Resolver.AddSubResolver(new ContextResolver(Kernel));
            Kernel.Resolver.AddSubResolver(new LoggingResolver());

            if (assemblies == null)
            {
                if (FacilityConfig == null)
                {
                    logger.Fatal("Configuration for Bijection Facility not found.");
                    throw new FacilityException("Sorry, but the Bijection Facility depends on a proper configuration node.");
                }

                IConfiguration assemblyConfig = FacilityConfig.Children["assemblies"];

                if (assemblyConfig == null || assemblyConfig.Children.Count == 0)
                {
                    logger.Fatal("No assembly specified on Bijection Facility config.");

                    throw new FacilityException("You need to specify at least one assembly that contains " +
                                                "the Inject decorated classes. For example, <assemblies><item>MyAssembly</item></assemblies>");
                }

                ConfigurationCollection assembliyConfigNodes = assemblyConfig.Children;

                this.assemblies = new Assembly[assembliyConfigNodes.Count];

                for (int i = 0; i < assembliyConfigNodes.Count; i++)
                {
                    IConfiguration assemblyNode = assembliyConfigNodes[i];
                    assemblies[i] = ObtainAssembly(assemblyNode.Value);
                }
            }

            // Added a ComponentCache Repository to track it
            Kernel.AddComponent("component.repository", typeof(ComponentRepository));
            Kernel.ComponentModelBuilder.AddContributor(new InjectionInspector());
            Kernel.ComponentCreated += Kernel_ComponentCreated;
            RegisterViewComponent();
            RegisterControllers();
        }
Example #22
0
        protected override void Init()
        {
            if (FacilityConfig == null)
            {
                throw new ConfigurationException("db4o facility requires an external configuration.");
            }

            Kernel.ComponentModelBuilder.AddContributor(new AutoDb4oTransactionInspector());
            Kernel.ComponentModelBuilder.AddContributor(new ObjectContainerActivatorOverrider());

            Kernel.AddComponent("db4o.transaction.autocommit.interceptor", typeof(AutoCommitInterceptor), typeof(AutoCommitInterceptor));

            Kernel.AddComponent("db4o.transaction.manager", typeof(ITransactionManager), typeof(Db4oTransactionManager));

            ConfigureAndAddContainer();
        }
Example #23
0
 private void RegisterControllers()
 {
     Kernel.AddComponent("BaseController", typeof(BaseController));
     foreach (Assembly assembly in assemblies)
     {
         foreach (Type type in assembly.GetExportedTypes())
         {
             if (!typeof(BaseController).IsAssignableFrom(type))
             {
                 continue;
             }
             if (AttributeUtil.ShouldSkipAutomaticRegistration(type))
             {
                 continue;
             }
             Kernel.AddComponent(type.Name, type, LifestyleType.Transient);
         }
     }
 }
Example #24
0
        private void ConfigureServerFacility()
        {
            Kernel.AddComponent("remoting.registry", typeof(RemotingRegistry));

            localRegistry = (RemotingRegistry)Kernel[typeof(RemotingRegistry)];

            String kernelUri = FacilityConfig.Attributes["registryUri"];

            if (kernelUri == null || kernelUri.Length == 0)
            {
                String message = "When the remote facility is configured as " +
                                 "server you must supply the URI for the component registry using the attribute 'registryUri'";
                throw new ConfigurationException(message);
            }

            RemotingServices.Marshal(localRegistry, kernelUri, typeof(RemotingRegistry));

            disconnectLocalRegistry = true;
        }
Example #25
0
        /// <summary>
        /// 注册Session管理器
        /// </summary>
        protected void RegisterSessionManager()
        {
            string defaultFlushMode = FacilityConfig.Attributes["defaultFlushMode"];

            if (defaultFlushMode != null && defaultFlushMode != string.Empty)
            {
                MutableConfiguration confignode = new MutableConfiguration("nhfacility.sessionmanager");

                IConfiguration properties =
                    confignode.Children.Add(new MutableConfiguration("parameters"));

                properties.Children.Add(new MutableConfiguration("DefaultFlushMode", defaultFlushMode));

                Kernel.ConfigurationStore.AddComponentConfiguration("nhfacility.sessionmanager", confignode);
            }

            Kernel.AddComponent("nhfacility.sessionmanager",
                                typeof(ISessionManager), typeof(DefaultSessionManager));
        }
Example #26
0
 private void ScanAssembly(Assembly asmtoscan)
 {
     foreach (Type t in asmtoscan.GetTypes())
     {
         Attribute attribute = Attribute.GetCustomAttribute(t, typeof(AutoscanComponentAttribute));
         if (attribute != null)
         {
             AutoscanComponentAttribute autoscanattribute = attribute as AutoscanComponentAttribute;
             Type serviceType = autoscanattribute.ServiceType;
             if (serviceType == null)
             {
                 serviceType = t.GetInterfaces()[0];
             }
             Kernel.AddComponent(
                 autoscanattribute.Id,
                 serviceType,
                 t,
                 autoscanattribute.LifestyleType);
         }
     }
 }
Example #27
0
        /// <summary>
        /// Initializes the MethodValidatorFacility
        /// </summary>
        protected override void Init()
        {
            IValidatorRegistry registry;

            if (Kernel.HasComponent(typeof(IValidatorRegistry)))
            {
                registry = Kernel.Resolve <IValidatorRegistry>();
            }
            else
            {
                registry = new CachedValidationRegistry();
            }

            IValidatorRegistry adapter = new ParameterValidatorRegistryAdapter(registry);

            Kernel.AddComponentInstance("methodValidator.metaStore", new MethodValidatorMetaStore(adapter));

            Kernel.AddComponent("methodValidator.interceptor", typeof(MethodValidatorInterceptor));
            Kernel.AddComponent("methodValidator.contributor", typeof(MethodValidationContributor));
            Kernel.ComponentModelBuilder.AddContributor(new MethodValidatorComponentInspector());
        }
Example #28
0
 public void SetUpServices()
 {
     base.Init();
     Kernel.AddComponent("namingservice", typeof(INamingService), typeof(NamingService));
 }
 protected override void Init()
 {
     Kernel.AddComponent <TransactionalInterceptor>();
     Kernel.ComponentModelBuilder.AddContributor(new TransactionalInterceptorContributor());
 }
 protected override void Init()
 {
     Kernel.AddComponent("security.interceptor", typeof(SecurityInterceptor));
     Kernel.ComponentModelBuilder.AddContributor(new SecurityComponentInspector());
     Kernel.AddComponent("security.manager", typeof(ISecurityManager), typeof(SecurityManager));
 }