Datei: NDODLL/Application/BuilderExtensions.cs
Last Commit (273289e)
			
| 1 | // | 
| 2 | // Copyright (c) 2002-2024 Mirko Matytschak | 
| 3 | // (www.netdataobjects.de) | 
| 4 | // | 
| 5 | // Author: Mirko Matytschak | 
| 6 | // | 
| 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated | 
| 8 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation | 
| 9 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the | 
| 10 | // Software, and to permit persons to whom the Software is furnished to do so, subject to the following | 
| 11 | // conditions: | 
| 12 | |
| 13 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions | 
| 14 | // of the Software. | 
| 15 | // | 
| 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED | 
| 17 | // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | 
| 18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | 
| 19 | // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 
| 20 | // DEALINGS IN THE SOFTWARE. | 
| 21 | |
| 22 | using System; | 
| 23 | using Microsoft.Extensions.Configuration; | 
| 24 | using Microsoft.Extensions.DependencyInjection; | 
| 25 | using Microsoft.Extensions.Hosting; | 
| 26 | using NDO.ProviderFactory; | 
| 27 | using NDO.Query; | 
| 28 | using NDO.SqlPersistenceHandling; | 
| 29 | |
| 30 | namespace NDO.Application | 
| 31 | { | 
| 32 | ····/// <summary> | 
| 33 | ····/// Startup extensions to integrate NDO into the Microsoft .NET application architecture | 
| 34 | ····/// </summary> | 
| 35 | ····public static class BuilderExtensions | 
| 36 | ····{ | 
| 37 | ········/// <summary> | 
| 38 | ········/// Call this method in your Startup class, so that NDO has a chance to register required services. | 
| 39 | ········/// </summary> | 
| 40 | ········/// <remarks> | 
| 41 | ········/// <code> | 
| 42 | ········/// public void ConfigureServices(IServiceCollection services) | 
| 43 | ········/// { | 
| 44 | ········///········... | 
| 45 | ········///········services.AddNdo(_env,_config); | 
| 46 | ········///········... | 
| 47 | ········/// } | 
| 48 | ········/// </code> | 
| 49 | ········/// </remarks> | 
| 50 | ········/// <param name="services"></param> | 
| 51 | ········/// <param name="hostEnvironment"></param> | 
| 52 | ········/// <param name="config"></param> | 
| 53 | ········public static void AddNdo( this IServiceCollection services, IHostEnvironment hostEnvironment, IConfiguration config ) | 
| 54 | ········{ | 
| 55 | ············services.AddNdoProviderFactory( hostEnvironment, config ); | 
| 56 | ············NDOApplication.Configuration = config; | 
| 57 | ············NDOApplication.HostEnvironment = hostEnvironment; | 
| 58 | ············services.AddTransient<IPersistenceHandler, SqlPersistenceHandler>(); | 
| 59 | ············services.AddTransient<RelationContextGenerator>(); | 
| 60 | ············services.AddTransient<IQueryGenerator, SqlQueryGenerator>(); | 
| 61 | ············services.AddScoped<IPersistenceHandlerManager, NDOPersistenceHandlerManager>(); | 
| 62 | ············services.AddSingleton<IPersistenceHandlerPool, NDOPersistenceHandlerPool>(); | 
| 63 | ············services.AddScoped<IMappingsAccessor, MappingsAccessor>(); | 
| 64 | ············services.AddTransient<INDOTransactionScope, NDOTransactionScope>(); | 
| 65 | ············services.AddScoped<IPersistenceManagerAccessor, PersistenceManagerAccessor>(); | 
| 66 | ········} | 
| 67 | |
| 68 | ········/// <summary> | 
| 69 | ········/// Call this method in your Startup class to give NDO the chance to use the IServiceProvider interface | 
| 70 | ········/// </summary> | 
| 71 | ········/// <remarks> | 
| 72 | ········/// In the Startup class of a web project write | 
| 73 | ········/// <code> | 
| 74 | ········/// public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | 
| 75 | ········/// { | 
| 76 | ········///········... | 
| 77 | ········///········app.ApplicationServices.UseNdo(); | 
| 78 | ········///········... | 
| 79 | ········/// } | 
| 80 | ········/// </code> | 
| 81 | ········/// If you have an IHostBuilder interface use this code: | 
| 82 | ········/// <code> | 
| 83 | ········/// var builder = Host.CreateDefaultBuilder(); | 
| 84 | ········/// ... | 
| 85 | ········/// builder.ConfigureServices( services => | 
| 86 | ········/// { | 
| 87 | ········///········services.UseNdo(); | 
| 88 | ········/// } ); | 
| 89 | ········/// </code> | 
| 90 | ········/// With CreateApplicationBuilder use this code | 
| 91 | ········/// <code> | 
| 92 | ········/// var builder = Host.CreateApplicationBuilder(); | 
| 93 | ········/// ... | 
| 94 | ········/// var services = builder.Services; | 
| 95 | ········/// services.UseNdo(); | 
| 96 | ········/// </code> | 
| 97 | ········/// </remarks> | 
| 98 | ········/// <param name="serviceProvider"></param> | 
| 99 | ········/// <returns>The IServiceProvider instance, passed as parameter.</returns> | 
| 100 | ········public static IServiceProvider UseNdo( this IServiceProvider serviceProvider ) | 
| 101 | ········{ | 
| 102 | ············serviceProvider.UseNdoProviderFactory(); | 
| 103 | ············NDOApplication.ServiceProvider = serviceProvider; | 
| 104 | ············return serviceProvider; | 
| 105 | ········} | 
| 106 | ····} | 
| 107 | } | 
| 108 | 
New Commit (e4584c5)
			
| 1 | // | 
| 2 | // Copyright (c) 2002-2024 Mirko Matytschak | 
| 3 | // (www.netdataobjects.de) | 
| 4 | // | 
| 5 | // Author: Mirko Matytschak | 
| 6 | // | 
| 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated | 
| 8 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation | 
| 9 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the | 
| 10 | // Software, and to permit persons to whom the Software is furnished to do so, subject to the following | 
| 11 | // conditions: | 
| 12 | |
| 13 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions | 
| 14 | // of the Software. | 
| 15 | // | 
| 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED | 
| 17 | // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | 
| 18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | 
| 19 | // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 
| 20 | // DEALINGS IN THE SOFTWARE. | 
| 21 | |
| 22 | using System; | 
| 23 | using Microsoft.Extensions.Configuration; | 
| 24 | using Microsoft.Extensions.DependencyInjection; | 
| 25 | using Microsoft.Extensions.Hosting; | 
| 26 | using NDO.ProviderFactory; | 
| 27 | using NDO.Query; | 
| 28 | using NDO.SqlPersistenceHandling; | 
| 29 | |
| 30 | namespace NDO.Application | 
| 31 | { | 
| 32 | ····/// <summary> | 
| 33 | ····/// Startup extensions to integrate NDO into the Microsoft .NET application architecture | 
| 34 | ····/// </summary> | 
| 35 | ····public static class BuilderExtensions | 
| 36 | ····{ | 
| 37 | ········/// <summary> | 
| 38 | ········/// Call this method in your Startup class, so that NDO has a chance to register required services. | 
| 39 | ········/// </summary> | 
| 40 | ········/// <remarks> | 
| 41 | ········/// <code> | 
| 42 | ········/// public void ConfigureServices(IServiceCollection services) | 
| 43 | ········/// { | 
| 44 | ········///········... | 
| 45 | ········///········services.AddNdo(_env,_config); | 
| 46 | ········///········... | 
| 47 | ········/// } | 
| 48 | ········/// </code> | 
| 49 | ········/// </remarks> | 
| 50 | ········/// <param name="services"></param> | 
| 51 | ········/// <param name="hostEnvironment"></param> | 
| 52 | ········/// <param name="config"></param> | 
| 53 | ········public static void AddNdo( this IServiceCollection services, IHostEnvironment hostEnvironment, IConfiguration config ) | 
| 54 | ········{ | 
| 55 | ············services.AddNdoProviderFactory( hostEnvironment, config ); | 
| 56 | ············NDOApplication.Configuration = config; | 
| 57 | ············NDOApplication.HostEnvironment = hostEnvironment; | 
| 58 | ············services.AddTransient<IPersistenceHandler, SqlPersistenceHandler>(); | 
| 59 | ············services.AddTransient<RelationContextGenerator>(); | 
| 60 | ············services.AddTransient<IQueryGenerator, SqlQueryGenerator>(); | 
| 61 | ············services.AddScoped<IPersistenceHandlerManager, NDOPersistenceHandlerManager>(); | 
| 62 | ············services.AddSingleton<IPersistenceHandlerPool, NDOPersistenceHandlerPool>(); | 
| 63 | ············services.AddScoped<IMappingsAccessor, MappingsAccessor>(); | 
| 64 | ············services.AddTransient<INDOTransactionScope, NDOTransactionScope>(); | 
| 65 | ············services.AddScoped<IPersistenceManagerAccessor, PersistenceManagerAccessor>(); | 
| 66 | ········} | 
| 67 | |
| 68 | ········/// <summary> | 
| 69 | ········/// Call this method in your Startup class to give NDO the chance to use the IServiceProvider interface | 
| 70 | ········/// </summary> | 
| 71 | ········/// <remarks> | 
| 72 | ········/// In the Startup class of a web project write | 
| 73 | ········/// <code> | 
| 74 | ········/// public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | 
| 75 | ········/// { | 
| 76 | ········///········... | 
| 77 | ········///········app.ApplicationServices.UseNdo(); | 
| 78 | ········///········... | 
| 79 | ········/// } | 
| 80 | ········/// </code> | 
| 81 | ········/// If you have an IHostBuilder interface use this code: | 
| 82 | ········/// <code> | 
| 83 | ········/// var builder = Host.CreateDefaultBuilder(); | 
| 84 | ········/// ... | 
| 85 | ········/// builder.ConfigureServices( services => | 
| 86 | ········/// { | 
| 87 | ········///········services.UseNdo(); | 
| 88 | ········/// } ); | 
| 89 | ········/// </code> | 
| 90 | ········/// With CreateApplicationBuilder use this code | 
| 91 | ········/// <code> | 
| 92 | ········/// var builder = Host.CreateApplicationBuilder(); | 
| 93 | ········/// ... | 
| 94 | ········/// var services = builder.Services; | 
| 95 | ········/// services.UseNdo(); | 
| 96 | ········/// </code> | 
| 97 | ········/// </remarks> | 
| 98 | ········/// <param name="serviceProvider"></param> | 
| 99 | ········/// <returns>The IServiceProvider instance, passed as parameter.</returns> | 
| 100 | ········public static IServiceProvider UseNdo( this IServiceProvider serviceProvider ) | 
| 101 | ········{ | 
| 102 | ············// Initializes the internal class NDOApplication of the ProviderFactory | 
| 103 | ············serviceProvider.UseNdoProviderFactory(); | 
| 104 | ············// Initializes the internal class NDOApplication of NDO.dll. | 
| 105 | ············NDOApplication.ServiceProvider = serviceProvider; | 
| 106 | ············return serviceProvider; | 
| 107 | ········} | 
| 108 | ····} | 
| 109 | } | 
| 110 |