Datei: NDODLL/Application/BuilderExtensions.cs

Last Commit (1e1255d)
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.AddSingleton<IPersistenceHandlerPool, NDOPersistenceHandlerPool>();
59 ············// These services are all transient, because there can be
60 ············// different PMs in one Request, which would share the
61 ············// scoped objects.
62 ············services.AddTransient<IPersistenceHandler, SqlPersistenceHandler>();
63 ············services.AddTransient<IQueryGenerator, SqlQueryGenerator>();
64 ············services.AddTransient<INDOTransactionScope, NDOTransactionScope>();
65 ········}
66
67 ········/// <summary>
68 ········/// Call this method in your Startup class to give NDO the chance to use the IServiceProvider interface
69 ········/// </summary>
70 ········/// <remarks>
71 ········/// In the Startup class of a web project write
72 ········/// <code>
73 ········/// public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
74 ········/// {
75 ········///········...
76 ········///········app.ApplicationServices.UseNdo();
77 ········///········...
78 ········/// }
79 ········/// </code>
80 ········/// If you have an IHostBuilder interface use this code:
81 ········/// <code>
82 ········/// var builder = Host.CreateDefaultBuilder();
83 ········/// ...
84 ········/// builder.ConfigureServices( services =>
85 ········/// {
86 ········///········services.UseNdo();
87 ········/// } );
88 ········/// </code>
89 ········/// With CreateApplicationBuilder use this code
90 ········/// <code>
91 ········/// var builder = Host.CreateApplicationBuilder();
92 ········/// ...
93 ········/// var services = builder.Services;
94 ········/// services.UseNdo();
95 ········/// </code>
96 ········/// </remarks>
97 ········/// <param name="serviceProvider"></param>
98 ········/// <returns>The IServiceProvider instance, passed as parameter.</returns>
99 ········public static IServiceProvider UseNdo( this IServiceProvider serviceProvider )
100 ········{
101 ············// Initializes the internal class NDOApplication of the ProviderFactory
102 ············serviceProvider.UseNdoProviderFactory();
103 ············// Initializes the internal class NDOApplication of NDO.dll.
104 ············NDOApplication.ServiceProvider = serviceProvider;
105 ············return serviceProvider;
106 ········}
107 ····}
108 }
109
New Commit (d0706b7)
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 ············// These services are all transient, because there can be
59 ············// different PMs in one Request, which would share the
60 ············// scoped objects.
61 ············services.AddTransient<IPersistenceHandler, SqlPersistenceHandler>();
62 ············services.AddTransient<IQueryGenerator, SqlQueryGenerator>();
63 ············services.AddTransient<INDOTransactionScope, NDOTransactionScope>();
64 ········}
65
66 ········/// <summary>
67 ········/// Call this method in your Startup class to give NDO the chance to use the IServiceProvider interface
68 ········/// </summary>
69 ········/// <remarks>
70 ········/// In the Startup class of a web project write
71 ········/// <code>
72 ········/// public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
73 ········/// {
74 ········///········...
75 ········///········app.ApplicationServices.UseNdo();
76 ········///········...
77 ········/// }
78 ········/// </code>
79 ········/// If you have an IHostBuilder interface use this code:
80 ········/// <code>
81 ········/// var builder = Host.CreateDefaultBuilder();
82 ········/// ...
83 ········/// builder.ConfigureServices( services =>
84 ········/// {
85 ········///········services.UseNdo();
86 ········/// } );
87 ········/// </code>
88 ········/// With CreateApplicationBuilder use this code
89 ········/// <code>
90 ········/// var builder = Host.CreateApplicationBuilder();
91 ········/// ...
92 ········/// var services = builder.Services;
93 ········/// services.UseNdo();
94 ········/// </code>
95 ········/// </remarks>
96 ········/// <param name="serviceProvider"></param>
97 ········/// <returns>The IServiceProvider instance, passed as parameter.</returns>
98 ········public static IServiceProvider UseNdo( this IServiceProvider serviceProvider )
99 ········{
100 ············// Initializes the internal class NDOApplication of the ProviderFactory
101 ············serviceProvider.UseNdoProviderFactory();
102 ············// Initializes the internal class NDOApplication of NDO.dll.
103 ············NDOApplication.ServiceProvider = serviceProvider;
104 ············return serviceProvider;
105 ········}
106 ····}
107 }
108