|
1 | 1 | using Disc.NET.Configuration; |
2 | 2 | using Disc.NET.Gateway; |
3 | | -using Microsoft.Extensions.Logging; |
4 | 3 |
|
5 | 4 | namespace Disc.NET |
6 | 5 | { |
7 | 6 | public class App |
8 | 7 | { |
9 | | - private ILogger<GatewayConnection> _logger; |
10 | | - public App() |
11 | | - { |
12 | | - _logger = CreateLogger(LogLevel.Information); |
13 | | - } |
14 | | - |
15 | | - public async Task RunAsync(AppConfiguration configuration) |
16 | | - { |
17 | | - if (configuration.UseContainer) |
18 | | - { |
19 | | - DiscNetContainer.GetInstance().RegisterDependencies(); |
20 | | - } |
21 | | - var gateway = new GatewayConnection(configuration,_logger); |
22 | | - await gateway.ConnectAsync(); |
23 | | - } |
| 8 | + private readonly AppConfiguration _appConfiguration; |
24 | 9 |
|
25 | | - public App WithDebugLogger() |
| 10 | + public App(AppConfiguration appConfiguration) |
26 | 11 | { |
27 | | - _logger = CreateLogger(LogLevel.Debug); |
28 | | - return this; |
| 12 | + _appConfiguration = appConfiguration; |
29 | 13 | } |
30 | 14 |
|
31 | | - private ILogger<GatewayConnection> CreateLogger(LogLevel level) |
| 15 | + public async Task RunAsync() |
32 | 16 | { |
33 | | - var loggerFactory = LoggerFactory.Create(builder => |
34 | | - { |
35 | | - builder.AddConsole(); |
36 | | - builder.SetMinimumLevel(level); |
37 | | - }); |
38 | | - |
39 | | - return loggerFactory.CreateLogger<GatewayConnection>(); |
40 | | - } |
41 | | - /// <summary> |
42 | | - /// Configures the container usage strategy for the application. |
43 | | - /// |
44 | | - /// By default, object creation is performed using the standard C# <see cref="Activator"/>, |
45 | | - /// which does not provide support for dependency injection. |
46 | | - /// |
47 | | - /// When this method is called, the application switches to using the Autofac container, |
48 | | - /// enabling full dependency injection support for registered components. |
49 | | - /// |
50 | | - /// In summary: |
51 | | - /// - Without calling this method → uses default Activator (no DI) |
52 | | - /// - Calling this method → enables Autofac and dependency injection |
53 | | - /// </summary> |
54 | | - /// <param name="appConfiguration"> |
55 | | - /// Application configuration instance where the container selection flag is stored. |
56 | | - /// </param> |
57 | | - /// <returns> |
58 | | - /// Returns the singleton instance of <see cref="DiscNetContainer"/> configured to use Autofac. |
59 | | - /// </returns> |
60 | | - public DiscNetContainer UseDependencyInjection(AppConfiguration appConfiguration) |
61 | | - { |
62 | | - appConfiguration.UseContainer = true; |
63 | | - return DiscNetContainer.GetInstance(); |
| 17 | + var gateway = new GatewayConnection(_appConfiguration); |
| 18 | + await gateway.ConnectAsync(); |
64 | 19 | } |
65 | | - |
66 | 20 | } |
67 | 21 |
|
68 | 22 | } |
0 commit comments