/// <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(); } }
public IEnumerable <ConceptInfoRestMetadata> GetConceptInfoRestMetadata(RhetosHost rhetosHost) { var dslModel = rhetosHost.GetRootContainer().Resolve <IDslModel>(); var domainObjectModel = rhetosHost.GetRootContainer().Resolve <IDomainObjectModel>(); var dataStructureReadParameters = rhetosHost.GetRootContainer().Resolve <IDataStructureReadParameters>(); DataStructureInfoMetadata CreateFromGenericController(Type genericControllerType, DataStructureInfo dataStructureInfo) { var parameters = dataStructureReadParameters.GetReadParameters(dataStructureInfo.FullName, true) .Select(parameter => Tuple.Create(parameter.Name, parameter.Type)) .ToArray(); var dataStructureInfoMetadata = new DataStructureInfoMetadata(parameters) { ControllerType = genericControllerType.MakeGenericType(domainObjectModel.GetType($"{dataStructureInfo.FullName}")), ControllerName = $"{dataStructureInfo.Module.Name}.{dataStructureInfo.Name}", RelativeRoute = $"{dataStructureInfo.Module.Name}/{dataStructureInfo.Name}", ApiExplorerGroupName = dataStructureInfo.Module.Name, }; return(dataStructureInfoMetadata); } var dataStructuresByWriteInfo = dslModel .FindByType <WriteInfo>() .Select(writeInfo => writeInfo.DataStructure) .Distinct() .ToHashSet(); Type DataStructureControllerType(DataStructureInfo dataStructureInfo) { if (dataStructureInfo is IWritableOrmDataStructure || dataStructuresByWriteInfo.Contains(dataStructureInfo)) { return(typeof(ReadWriteDataApiController <>)); } else if (IsDataStructureTypeSupported(dataStructureInfo)) { return(typeof(ReadDataApiController <>)); } return(null); } var restMetadata = dslModel .FindByType <DataStructureInfo>() .Select(dataStructureInfo => (dataStructureInfo, controllerType: DataStructureControllerType(dataStructureInfo))) .Where(implementation => implementation.controllerType != null) .Select(implementation => CreateFromGenericController(implementation.controllerType, implementation.dataStructureInfo)); return(restMetadata); }
private void ExecuteCommand(string rhetosHostAssemblyPath, string password) { var hostServices = RhetosHost.GetHostServices( rhetosHostAssemblyPath, rhetosHostBuilder => rhetosHostBuilder.ConfigureContainer(builder => builder.RegisterType <ConsoleLogProvider>().As <ILogProvider>().SingleInstance()), (hostBuilderContext, serviceCollection) => serviceCollection.AddScoped <IUserInfo, ProcessUserInfo>()); using (var scope = hostServices.CreateScope()) { scope.ServiceProvider.GetService <IRhetosComponent <AdminUserInitializer> >().Value.Initialize(); SetUpAdminAccount(scope.ServiceProvider, password); scope.ServiceProvider.GetService <IRhetosComponent <IUnitOfWork> >().Value.CommitAndClose(); } }
public IEnumerable <ConceptInfoRestMetadata> GetConceptInfoRestMetadata(RhetosHost rhetosHost) { var dslModel = rhetosHost.GetRootContainer().Resolve <IDslModel>(); var domainObjectModel = rhetosHost.GetRootContainer().Resolve <IDomainObjectModel>(); var restMetadata = dslModel .FindByType <ReportDataInfo>() .Select(reportDataInfo => new ConceptInfoRestMetadata() { ControllerType = typeof(ReportApiController <>).MakeGenericType(domainObjectModel.GetType($"{reportDataInfo.FullName}")), ControllerName = $"{reportDataInfo.Module.Name}.{reportDataInfo.Name}", RelativeRoute = $"{reportDataInfo.Module.Name}/{reportDataInfo.Name}", ApiExplorerGroupName = reportDataInfo.Module.Name }); return(restMetadata); }
public IEnumerable <ConceptInfoRestMetadata> GetConceptInfoRestMetadata(RhetosHost rhetosHost) { var dslModel = rhetosHost.GetRootContainer().Resolve <IDslModel>(); var domainObjectModel = rhetosHost.GetRootContainer().Resolve <IDomainObjectModel>(); var restMetadata = dslModel .FindByType <DataStructureInfo>() .Where(dataStructureInfo => dataStructureInfo.Module.Name == "AspNetDemo") .Select(dataStructureInfo => new ConceptInfoRestMetadata() { ControllerType = typeof(RhetosExtendedController <>).MakeGenericType(domainObjectModel.GetType($"{dataStructureInfo.FullName}")), ControllerName = $"{dataStructureInfo.Module.Name}.{dataStructureInfo.Name}", RelativeRoute = $"{dataStructureInfo.Module.Name}/{dataStructureInfo.Name}", ApiExplorerGroupName = dataStructureInfo.Module.Name, }); return(restMetadata); }
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 ControllerRestInfoRepository CreateControllerRestInfoRepository(RhetosHost rhetosHost, RestApiOptions options) { var controllerRepository = new ControllerRestInfoRepository(); foreach (var conceptInfoRestMetadataProvider in options.ConceptInfoRestMetadataProviders) { var metadataFromProvider = conceptInfoRestMetadataProvider.GetConceptInfoRestMetadata(rhetosHost); foreach (var metadataItem in metadataFromProvider) { controllerRepository.ControllerConceptInfo.Add(metadataItem.ControllerType, metadataItem); } } // transform all group names if (options.GroupNameMapper != null) { foreach (var restMetadata in controllerRepository.ControllerConceptInfo.Values) { restMetadata.ApiExplorerGroupName = options.GroupNameMapper.Invoke(restMetadata.ConceptInfo, restMetadata.ApiExplorerGroupName); } } return(controllerRepository); }
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 RhetosAspNetServiceCollectionBuilder(IServiceCollection serviceCollection, RhetosHost rhetosHost) { Services = serviceCollection; RhetosHost = rhetosHost; }
public RhetosScopeServiceProvider(RhetosHost rhetosHost, IUserInfo rhetosUser) { unitOfWorkScope = rhetosHost.CreateScope(builder => builder.RegisterInstance(rhetosUser)); }