/// <summary> /// Note: /// This method does not conform to the standard IoC design pattern. /// It uses IoC container directly because it needs to handle a special scope control (separate database connections) and error handling. /// </summary> public static void ExecuteInitializer(RhetosHost container, Type initializerType, ILogProvider logProvider) { var logger = logProvider.GetLogger(nameof(ApplicationInitialization)); using (var scope = container.CreateScope()) { logger.Info($"Initialization {initializerType.Name}."); var initializers = scope.Resolve <IPluginsContainer <IServerInitializer> >().GetPlugins(); IServerInitializer initializer = initializers.Single(i => i.GetType() == initializerType); initializer.Initialize(); scope.CommitAndClose(); } }
private void InitializeUnitOfWorkScope() { if (_transactionScope == null) { if (_rhetosHost == null) { lock (_rhetosHostInitializationLock) if (_rhetosHost == null) { _rhetosHost = RhetosHost.CreateFrom(_rhetosAppAssemblyPath, rhetosHostBuilder => { rhetosHostBuilder.UseBuilderLogProvider(new ConsoleLogProvider()) .ConfigureConfiguration(configurationBuilder => configurationBuilder.AddConfigurationManagerConfiguration()); }); } } _transactionScope = _rhetosHost.CreateScope(InitializeSession); } }
private static void RunCommandSequence(RhetosHost rhetosHost) { using (var scope = rhetosHost.CreateScope()) { var processingEngine = scope.Resolve <IProcessingEngine>(); var readCommand = new ReadCommandInfo() { DataSource = "AspNetDemo.DemoEntity", ReadRecords = true }; var result = processingEngine.Execute(new List <ICommandInfo>() { readCommand }); var resultData = result.CommandResults.Single().Data.Value as ReadCommandResult; var deleteCommand = new SaveEntityCommandInfo() { Entity = "AspNetDemo.DemoEntity", DataToDelete = resultData.Records.Cast <IEntity>().ToArray() }; Console.WriteLine($"Deleting {resultData.Records.Length} records."); processingEngine.Execute(new List <ICommandInfo>() { deleteCommand }); scope.CommitAndClose(); } using (var scope = rhetosHost.CreateScope()) { var processingEngine = scope.Resolve <IProcessingEngine>(); var readCommand = new ReadCommandInfo() { DataSource = "AspNetDemo.DemoEntity", ReadRecords = true }; var result = processingEngine.Execute(new List <ICommandInfo>() { readCommand }); var resultData = result.CommandResults.Single().Data.Value as ReadCommandResult; Console.WriteLine($"Reading entities Count={resultData.Records.Length}."); var insertCommand = new SaveEntityCommandInfo() { Entity = "AspNetDemo.DemoEntity", DataToInsert = new[] { new AspNetDemo_DemoEntity() { Name = "not_saved" } } }; Console.WriteLine($"Inserting entity without committing transaction."); processingEngine.Execute(new List <ICommandInfo>() { insertCommand }); } using (var scope = rhetosHost.CreateScope()) { var processingEngine = scope.Resolve <IProcessingEngine>(); var readCommand = new ReadCommandInfo() { DataSource = "AspNetDemo.DemoEntity", ReadRecords = true }; var result = processingEngine.Execute(new List <ICommandInfo>() { readCommand }); var resultData = result.CommandResults.Single().Data.Value as ReadCommandResult; Console.WriteLine($"Reading entities Count={resultData.Records.Length}."); var insertCommand = new SaveEntityCommandInfo() { Entity = "AspNetDemo.DemoEntity", DataToInsert = new[] { new AspNetDemo_DemoEntity() { Name = "InsertedEntityName" } } }; Console.WriteLine($"Inserting entity with commit."); processingEngine.Execute(new List <ICommandInfo>() { insertCommand }); scope.CommitAndClose(); } using (var scope = rhetosHost.CreateScope()) { var processingEngine = scope.Resolve <IProcessingEngine>(); var readCommand = new ReadCommandInfo() { DataSource = "AspNetDemo.DemoEntity", ReadRecords = true }; var result = processingEngine.Execute(new List <ICommandInfo>() { readCommand }); var resultData = result.CommandResults.Single().Data.Value as ReadCommandResult; Console.WriteLine($"Reading entities Count={resultData.Records.Length}."); Console.WriteLine(JsonConvert.SerializeObject(resultData, Formatting.Indented)); } }
public RhetosScopeServiceProvider(RhetosHost rhetosHost, IUserInfo rhetosUser) { unitOfWorkScope = rhetosHost.CreateScope(builder => builder.RegisterInstance(rhetosUser)); }