-
Notifications
You must be signed in to change notification settings - Fork 11
/
AutofacConfig.cs
52 lines (44 loc) · 1.76 KB
/
AutofacConfig.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
using System;
using System.Reflection;
using System.Web.Http;
using Autofac;
using Autofac.Integration.WebApi;
using AutofacSerilogIntegration;
namespace ReferenceProject
{
/// <summary>
/// Represent Autofac configuration.
/// </summary>
public class AutofacConfig
{
/// <summary>
/// Configured instance of <see cref="IContainer"/>
/// <remarks><see cref="AutofacConfig.Configure"/> must be called before trying to get Container instance.</remarks>
/// </summary>
protected internal static IContainer Container;
/// <summary>
/// Initializes and configures instance of <see cref="IContainer"/>.
/// </summary>
/// <param name="config"></param>
public static void Configure(HttpConfiguration config)
{
if (config == null)
throw new ArgumentNullException(nameof(config));
var builder = new ContainerBuilder();
// Register your Web API controllers.
builder.RegisterApiControllers(Assembly.GetExecutingAssembly()).InstancePerRequest();
builder.RegisterLogger();
builder.RegisterInstance(AutoMapperConfig.Configure(config));
RegisterServices(builder);
Container = builder.Build();
config.DependencyResolver = new AutofacWebApiDependencyResolver(Container);
}
#pragma warning disable RECS0154 // Parameter is never used
private static void RegisterServices(ContainerBuilder builder)
#pragma warning restore RECS0154 // Parameter is never used
{
// TODO: Register additional services for injection
// For more information see https://github.com/drwatson1/AspNet-WebApi/wiki#dependency-injection
}
}
}