-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactory.cs
More file actions
42 lines (36 loc) · 1.75 KB
/
Copy pathFactory.cs
File metadata and controls
42 lines (36 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using System;
namespace NetCoreStack.Wcf
{
public class Factory
{
private IServiceCollection _services;
private IApplicationBuilder _appBuilder;
private StartupMethods _methods;
private IHostingEnvironment _hostingEnvironment;
public static IServiceProvider ApplicationServices { get; private set; }
public Factory()
{
_services = new ServiceCollection();
_appBuilder = new DefaultApplicationBuilder();
_hostingEnvironment = new HostingEnvironment();
_services.AddSingleton<IApplicationBuilder>(_appBuilder);
_services.AddSingleton<IHostingEnvironment>(_hostingEnvironment);
ApplicationServices = _services.BuildServiceProvider();
_appBuilder.ApplicationServices = ApplicationServices;
}
public void Build<TStartup>()
{
_methods = StartupLoader.LoadMethods(ApplicationServices, typeof(TStartup), _hostingEnvironment.EnvironmentName);
_services.AddOptions();
_services.AddSingleton<IServiceInstanceInvokeFilter, DefaultServiceInstanceInvokeFilter>();
_services.TryAdd(ServiceDescriptor.Scoped<IIdentityProvider, DefaultIdentityProvider>());
_services.TryAdd(ServiceDescriptor.Scoped<IServiceMethodExceptionFilter, DefaultServiceMethodExceptionFilter>());
_services.TryAdd(ServiceDescriptor.Scoped<IServiceLogger, DefaultServiceLogger>());
_methods.ConfigureServicesDelegate(_services);
_methods.ConfigureDelegate(_appBuilder);
ApplicationServices = _services.BuildServiceProvider();
}
}
}