Beispiel #1
0
        /// <summary>
        /// 重新构建.
        /// </summary>
        /// <param name="serviceContainer">The service container.</param>
        /// <returns>System.Nullable&lt;ValueTuple&lt;List&lt;Type&gt;, IEnumerable&lt;System.String&gt;&gt;&gt;.</returns>
        public ValueTuple <List <Type>, IEnumerable <string> >?ReBuild(ContainerBuilder serviceContainer)
        {
            ValueTuple <List <Type>, IEnumerable <string> >?result = null;
            var serviceBuilder = new ServiceBuilder(serviceContainer);
            var virtualPaths   = new List <string>();
            var rootPath       = string.IsNullOrEmpty(AppConfig.ServerOptions.RootPath)
                ? AppContext.BaseDirectory
                : AppConfig.ServerOptions.RootPath;

            if (_serviceEngine != null)
            {
                if (_serviceEngine.ModuleServiceLocationFormats != null)
                {
                    var paths = GetPaths(_serviceEngine.ModuleServiceLocationFormats);
                    paths = paths?.Where(p =>
                                         (Directory.GetLastWriteTime(Path.Combine(rootPath, p)) - _lastBuildTime).TotalSeconds > 0)
                            .ToArray();
                    if (paths == null || paths.Length == 0)
                    {
                        return(null);
                    }

                    if (_logger.IsEnabled(LogLevel.Debug))
                    {
                        _logger.LogDebug($"准备加载路径${string.Join(',', paths)}下的业务模块。");
                    }

                    serviceBuilder.RegisterServices(paths);
                    serviceBuilder.RegisterServiceBus(paths);
                    result = new ValueTuple <List <Type>, IEnumerable <string> >(serviceBuilder.GetInterfaceService(paths),
                                                                                 serviceBuilder.GetDataContractName(paths));
                }

                if (_serviceEngine.ComponentServiceLocationFormats != null)
                {
                    var paths = GetPaths(_serviceEngine.ComponentServiceLocationFormats);
                    paths = paths?.Where(p => (Directory.GetLastWriteTime(p) - _lastBuildTime).TotalSeconds > 0)
                            .ToArray();
                    if (paths != null && paths.Length > 0)
                    {
                        if (_logger.IsEnabled(LogLevel.Debug))
                        {
                            _logger.LogDebug($"准备加载路径${string.Join(',', paths)}下的组件模块。");
                        }

                        serviceBuilder.RegisterModules(paths);
                    }
                }

                _lastBuildTime = DateTime.Now;
            }

            return(result);
        }