/// <summary> /// 开始执行框架初始化 /// </summary> /// <param name="iocBuilder">依赖注入构建器</param> public void Initialize(IIocBuilder iocBuilder) { iocBuilder.CheckNotNull("iocBuilder"); OSharpConfig config = OSharpConfig.Instance; //依赖注入初始化 IServiceProvider provider = iocBuilder.Build(); //对象映射功能初始化 IMappersBuilder mappersBuilder = provider.GetService <IMappersBuilder>(); IMapper mapper = provider.GetService <IMapper>(); if (!_mapperInitialized && mapper != null) { if (mappersBuilder != null) { IEnumerable <IMapTuple> mapTuples = provider.GetServices <IMapTuple>(); mappersBuilder.Build(mapTuples); } MapperExtensions.SetMaper(mapper); _mapperInitialized = true; } //日志功能初始化 IBasicLoggingInitializer loggingInitializer = provider.GetService <IBasicLoggingInitializer>(); if (!_basicLoggingInitialized && loggingInitializer != null) { loggingInitializer.Initialize(config.LoggingConfig); _basicLoggingInitialized = true; } //数据库初始化 IDatabaseInitializer databaseInitializer = provider.GetService <IDatabaseInitializer>(); if (!_databaseInitialized && databaseInitializer != null) { databaseInitializer.Initialize(config.DataConfig); _databaseInitialized = true; } //实体信息初始化 IEntityInfoHandler entityInfoHandler = provider.GetService <IEntityInfoHandler>(); if (!_entityInfoInitialized && entityInfoHandler != null) { entityInfoHandler.Initialize(); _entityInfoInitialized = true; } //功能信息初始化 IFunctionHandler functionHandler = provider.GetService <IFunctionHandler>(); if (functionHandler != null) { functionHandler.Initialize(); } }
/// <summary> /// 开始执行框架初始化 /// </summary> /// <param name="iocBuilder">依赖注入构建器</param> public void Initialize(IIocBuilder iocBuilder) { iocBuilder.CheckNotNull("iocBuilder"); OSharpConfig config = OSharpConfig.Instance; //依赖注入初始化 IServiceProvider provider = iocBuilder.Build(); //对象映射功能初始化 IMappersBuilder mappersBuilder = provider.GetService <IMappersBuilder>(); IMapper mapper = provider.GetService <IMapper>(); if (!_mapperInitialized) { if (mappersBuilder != null) { IEnumerable <IMapTuple> mapTuples = provider.GetServices <IMapTuple>(); mappersBuilder.Build(mapTuples); } if (mapper != null) { MapperExtensions.SetMaper(mapper); } _mapperInitialized = true; } //日志功能初始化 IBasicLoggingInitializer loggingInitializer = provider.GetService <IBasicLoggingInitializer>(); if (!_basicLoggingInitialized && loggingInitializer != null) { loggingInitializer.Initialize(config.LoggingConfig); _basicLoggingInitialized = true; } //数据库初始化 IDatabaseInitializer databaseInitializer = provider.GetService <IDatabaseInitializer>(); if (!_databaseInitialized) { if (databaseInitializer == null) { throw new InvalidOperationException(Resources.FrameworkInitializer_DatabaseInitializeIsNull); } databaseInitializer.Initialize(config.DataConfig); _databaseInitialized = true; } //实体信息初始化 if (!_entityInfoInitialized) { IEntityInfoHandler entityInfoHandler = provider.GetService <IEntityInfoHandler>(); if (entityInfoHandler == null) { throw new InvalidOperationException(Resources.FrameworkInitializer_EntityInfoHandlerIsNull); } entityInfoHandler.Initialize(); _entityInfoInitialized = true; } //功能信息初始化 IFunctionHandler functionHandler = provider.GetService <IFunctionHandler>(); if (functionHandler == null) { throw new InvalidOperationException(Resources.FrameworkInitializer_FunctionHandlerIsNull); } functionHandler.Initialize(); }