OpenAuth.Net/OpenAuth.Mvc/AutofacExt.cs

67 lines
2.4 KiB
C#
Raw Normal View History

2015-10-26 21:58:12 +08:00
// ***********************************************************************
// Assembly : OpenAuth.Mvc
// Author : yubaolee
// Created : 10-26-2015
//
// Last Modified By : yubaolee
// Last Modified On : 10-26-2015
// ***********************************************************************
// <copyright file="AutofacExt.cs" company="www.cnblogs.com/yubaolee">
// Copyright (c) www.cnblogs.com/yubaolee. All rights reserved.
// </copyright>
// <summary>IOC<4F><43>ʼ<EFBFBD><CABC></summary>
// ***********************************************************************
using Autofac;
2015-11-13 23:25:46 +08:00
using Autofac.Configuration;
2015-10-26 21:58:12 +08:00
using Autofac.Integration.Mvc;
using OpenAuth.App;
2015-11-19 21:49:39 +08:00
using System.Reflection;
using System.Web.Mvc;
2015-12-02 16:28:01 +08:00
using OpenAuth.Domain.Interface;
using OpenAuth.Repository;
2015-10-26 21:58:12 +08:00
namespace OpenAuth.Mvc
{
internal static class AutofacExt
2015-10-26 21:58:12 +08:00
{
public static void InitAutofac()
{
var builder = new ContainerBuilder();
2015-12-02 16:28:01 +08:00
//<2F><><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>
builder.RegisterGeneric(typeof(BaseRepository<>)).As(typeof(IRepository<>));
//Ӧ<>ò<EFBFBD>ע<EFBFBD><D7A2>
2015-11-19 21:49:39 +08:00
builder.RegisterModule(new ConfigurationSettingsReader("autofac"));
2015-10-26 21:58:12 +08:00
builder.RegisterType<LoginApp>();
builder.RegisterType<OrgManagerApp>();
2015-11-13 21:33:53 +08:00
builder.RegisterType<UserManagerApp>();
2015-11-19 21:49:39 +08:00
builder.RegisterType<RoleManagerApp>();
2015-11-21 23:56:39 +08:00
builder.RegisterType<ModuleManagerApp>();
2015-12-02 16:28:01 +08:00
builder.RegisterType<ModuleElementManagerApp>();
2015-10-26 21:58:12 +08:00
// Register your MVC controllers.
2015-11-13 21:33:53 +08:00
builder.RegisterControllers(typeof(MvcApplication).Assembly);
2015-10-26 21:58:12 +08:00
// OPTIONAL: Register model binders that require DI.
builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
builder.RegisterModelBinderProvider();
// OPTIONAL: Register web abstractions like HttpContextBase.
builder.RegisterModule<AutofacWebTypesModule>();
// OPTIONAL: Enable property injection in view pages.
builder.RegisterSource(new ViewRegistrationSource());
// OPTIONAL: Enable property injection into action filters.
builder.RegisterFilterProvider();
// Set the dependency resolver to be Autofac.
var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
}
}
}