init Autofac
This commit is contained in:
@@ -98,6 +98,7 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="App_Start\Bootstrapper.cs" />
|
||||
<Compile Include="App_Start\WebApiConfig.cs" />
|
||||
<Compile Include="Controllers\ValuesController.cs" />
|
||||
<Compile Include="Global.asax.cs">
|
||||
|
||||
31
API/API/App_Start/Bootstrapper.cs
Normal file
31
API/API/App_Start/Bootstrapper.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using Autofac;
|
||||
using Autofac.Integration.WebApi;
|
||||
using System.Reflection;
|
||||
using System.Web.Http;
|
||||
|
||||
namespace API.App_Start
|
||||
{
|
||||
/// <remarks>
|
||||
/// https://autofaccn.readthedocs.io/en/latest/integration/webapi.html#quick-start
|
||||
/// </remarks>
|
||||
public class Bootstrapper
|
||||
{
|
||||
public void InitContainer() {
|
||||
var config = GlobalConfiguration.Configuration;
|
||||
var builder = new ContainerBuilder();
|
||||
builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
|
||||
builder.RegisterWebApiFilterProvider(config);
|
||||
builder.RegisterWebApiModelBinderProvider();
|
||||
|
||||
RegisterServices(builder);
|
||||
|
||||
var container = builder.Build();
|
||||
config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
|
||||
}
|
||||
|
||||
private void RegisterServices(ContainerBuilder builder) {
|
||||
// ... builder.RegisterType<object>();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user