-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathServices.cs
57 lines (46 loc) · 1.83 KB
/
Services.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
54
55
56
57
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting.Internal;
using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.ObjectPool;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
namespace Meadow.CoverageReport
{
public static class Services
{
public static readonly ServiceProvider Provider;
static readonly string ApplicationName = typeof(Services).Assembly.GetName().Name;
static readonly IFileProvider FileProvider = new EmbeddedFileProvider(typeof(Services).Assembly);
static Services()
{
var services = new ServiceCollection();
services.AddSingleton<DiagnosticSource, SilentDiagnosticSource>();
services.AddSingleton<IHostingEnvironment>(new HostingEnvironment { ApplicationName = ApplicationName });
services.AddSingleton<ObjectPoolProvider, DefaultObjectPoolProvider>();
services.AddLogging();
services.AddSingleton<IViewRender, ViewRender>();
services.AddSingleton<CoveragePageRenderer>();
services
.AddMvcCore()
.AddRazorViewEngine(options =>
{
options.ViewLocationFormats.Add("/Views/{0}.cshtml");
options.FileProviders.Clear();
options.FileProviders.Add(FileProvider);
});
Provider = services.BuildServiceProvider();
}
internal class SilentDiagnosticSource : DiagnosticSource
{
public override void Write(string name, object value)
{
// Do nothing
}
public override bool IsEnabled(string name) => true;
}
}
}