-
Notifications
You must be signed in to change notification settings - Fork 137
/
Copy pathServiceLocator.cs
53 lines (42 loc) · 1.56 KB
/
ServiceLocator.cs
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
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.IO;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using Raven.Documentation.Cli.Tasks;
namespace Raven.Documentation.Cli
{
internal static class ServiceLocator
{
private static ServiceProvider Provider { get; set; }
public static T Resolve<T>()
{
return (T)Provider.GetService(typeof(T));
}
public static object Resolve(Type t)
{
return Provider.GetService(t);
}
public static void Configure()
{
var serviceCollection = new ServiceCollection();
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", false)
.Build();
var loggerFactory = new LoggerFactory()
.AddNLog();
serviceCollection.AddSingleton(loggerFactory);
serviceCollection.AddLogging();
serviceCollection.AddOptions();
var settings = new Settings();
configuration.Bind(settings);
serviceCollection.AddSingleton(settings);
serviceCollection.AddSingleton<Startup>();
serviceCollection.AddScoped<ParseArticlesTask>();
serviceCollection.AddScoped<ParseDocumentationTask>();
Provider = serviceCollection.BuildServiceProvider();
}
}
}