/// <summary>
        /// 初始化管理服务
        /// </summary>
        public static void AddJoyOIManagement(
            this IServiceCollection services, JoyOIManagementConfiguration configuration)
        {
            // 注册配置
            configuration.AfterLoaded();
            services.AddSingleton(configuration);

            // 注册服务
            services.AddTransient <IRepository <ActorEntity, Guid>, EFCoreRepository <ActorEntity, Guid> >();
            services.AddTransient <IRepository <BlobEntity, Guid>, EFCoreRepository <BlobEntity, Guid> >();
            services.AddTransient <IRepository <StateMachineEntity, Guid>, EFCoreRepository <StateMachineEntity, Guid> >();
            services.AddTransient <IRepository <StateMachineInstanceEntity, Guid>, EFCoreRepository <StateMachineInstanceEntity, Guid> >();
            services.AddTransient <IActorService, ActorService>();
            services.AddTransient <IBlobService, BlobService>();
            services.AddTransient <IStateMachineService, StateMachineService>();
            services.AddTransient <IStateMachineInstanceService, StateMachineInstanceService>();
            services.AddSingleton <IStateMachineInstanceStore, StateMachineInstanceStore>();
            services.AddSingleton <IDockerNodeStore, DockerNodeStore>();
            services.AddTransient <IDockerNodeService, DockerNodeService>();
            services.AddSingleton <IDynamicCompileService, DynamicCompileService>();
            services.AddSingleton <INotificationService, NotificationService>();

            // 静态功能
            InitializeStaticFunctions();
        }
Example #2
0
        public TestServiceBase()
        {
            var dir = Environment.CurrentDirectory;

            while (!File.Exists(Path.Combine(dir, "appsettings.json")))
            {
                dir = Path.GetDirectoryName(dir);
            }
            Environment.CurrentDirectory = dir;
            JoyOIManagementServiceCollectionExtensions.InitializeStaticFunctions();
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Environment.CurrentDirectory)
                          .AddJsonFile("appsettings.json");
            var configuration = builder.Build();

            _configuration = new JoyOIManagementConfiguration();
            configuration.GetSection("JoyOIManagement").Bind(_configuration);
            _configuration.AfterLoaded();
            _storage = new DummyStorage();
            // 数据库除错代码
            if (false)
            {
#pragma warning disable CS0162
                _storage.OnSaveChanges = (storage) =>
                {
                    var stackTrace = new StackTrace().ToString();
                    var tables     = JsonConvert.SerializeObject(storage.Tables, Formatting.Indented);
                    File.AppendAllText($"e:\\mgmtsvc_dblog_{Process.GetCurrentProcess().Id}.txt",
                                       $"{stackTrace}\r\n{tables}\r\n=====================================================\r\n\r\n");
                };
#pragma warning restore CS0162
            }
        }