Beispiel #1
0
        /// <summary>加入对象映射组件</summary>
        private void LoadObjectMapper(IKernel kernel, Assembly implementsAssembly, ObjectMapperLoaderConfig config)
        {
            var loader = implementsAssembly.CreateInterfaceInstance <IServiceLoader <ObjectMapperLoaderConfig> >();

            loader.Initialize(kernel, config);
        }
Beispiel #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();
        }
Beispiel #3
0
 /// <summary>设置对象映射配置</summary>
 public virtual void SetObjectMapperConfig(ObjectMapperLoaderConfig config)
 {
     //自定义配置
 }