Esempio n. 1
0
        /// <summary>加入绑定注入组件</summary>
        private void LoadBindingInject(IKernel kernel, Assembly implementsAssembly, BindingInjectLoaderConfig config)
        {
            var loader = implementsAssembly.CreateInterfaceInstance <IServiceLoader <BindingInjectLoaderConfig> >();

            loader.Initialize(kernel, config);
        }
Esempio n. 2
0
        /// <summary>初始化</summary>
        public virtual void Initialize()
        {
            //初始化容器
            if (Kernel == null)
            {
                if (!this.EnableWeb)
                {
                    var settings = new NinjectSettings();
                    settings.ExtensionSearchPatterns = new string[] { "Ninject.Extensions.*.dll" };
                    Kernel = new StandardKernel(settings);
                }
                else
                {
                    Kernel = new StandardKernel();
                }
            }
            var kernel = Kernel;

            kernel.Bind <IServiceProvider>().ToConstant(kernel);
            var implementsAssembly = Assembly.Load(this.ImplementsAssembly);
            //加载日志组件
            var loggingLoaderConfig = new LoggingLoaderConfig();

            SetLogggingConfig(loggingLoaderConfig);
            if (loggingLoaderConfig.Enable)
            {
                LoadLoggging(kernel, implementsAssembly, loggingLoaderConfig);
            }
            //加载异常组件
            var exceptionLoaderConfig = new ExceptionLoaderConfig();

            SetExceptionConfig(exceptionLoaderConfig);
            if (exceptionLoaderConfig.Enable)
            {
                LoadException(kernel, implementsAssembly, exceptionLoaderConfig);
            }
            //加载缓存组件
            var cacheLoaderConfig = new CacheLoaderConfig();

            SetCacheConfig(cacheLoaderConfig);
            if (cacheLoaderConfig.Enable)
            {
                LoadCache(kernel, implementsAssembly, cacheLoaderConfig);
            }
            //加载仓储数据访问组件
            var repositoryLoaderConfig = new RepositoryLoaderConfig();

            SetRepositoryConfig(repositoryLoaderConfig);
            if (repositoryLoaderConfig.Enable)
            {
                kernel.Bind <IEventBus>().ToConstant(SimpleEventBus.GetDefaultEventBus());
                LoadRepository(kernel, implementsAssembly, repositoryLoaderConfig);
            }
            //加载对象自动映射组件
            var objectMapperLoaderConfig = new ObjectMapperLoaderConfig();

            SetObjectMapperConfig(objectMapperLoaderConfig);
            if (objectMapperLoaderConfig.Enable)
            {
                LoadObjectMapper(kernel, implementsAssembly, objectMapperLoaderConfig);
            }
            //按约定注入绑定
            var bindingInjectLoaderConfig = new BindingInjectLoaderConfig();

            SetBindingInjectConfig(bindingInjectLoaderConfig);
            if (bindingInjectLoaderConfig.Enable)
            {
                LoadBindingInject(kernel, implementsAssembly, bindingInjectLoaderConfig);
            }
            //JSON序列化设置
            //JsonUtil.DefaultUseCamelCaseNamingStrategy();
        }
Esempio n. 3
0
 /// <summary>设置绑定注入配置</summary>
 public virtual void SetBindingInjectConfig(BindingInjectLoaderConfig config)
 {
     config.EnableWeb = this.EnableWeb;
 }