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>
|
2016-01-05 10:03:35 +08:00
|
|
|
|
// <summary>IOC扩展</summary>
|
2015-10-26 21:58:12 +08:00
|
|
|
|
// ***********************************************************************
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
{
|
2015-11-30 17:44:42 +08:00
|
|
|
|
internal static class AutofacExt
|
2015-10-26 21:58:12 +08:00
|
|
|
|
{
|
|
|
|
|
public static void InitAutofac()
|
|
|
|
|
{
|
|
|
|
|
var builder = new ContainerBuilder();
|
|
|
|
|
|
2016-01-05 10:03:35 +08:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>
|
2015-12-02 16:28:01 +08:00
|
|
|
|
builder.RegisterGeneric(typeof(BaseRepository<>)).As(typeof(IRepository<>));
|
|
|
|
|
|
2016-01-05 10:03:35 +08:00
|
|
|
|
//Ӧ<>ò<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-12-16 22:52:23 +08:00
|
|
|
|
builder.RegisterType<CategoryManagerApp>();
|
2015-12-19 23:02:10 +08:00
|
|
|
|
builder.RegisterType<ResourceManagerApp>();
|
2015-12-02 16:28:01 +08:00
|
|
|
|
|
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));
|
|
|
|
|
}
|
2015-12-16 22:52:23 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2016-01-05 10:03:35 +08:00
|
|
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ
|
2015-12-16 22:52:23 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
|
|
public static T GetFromFac<T>()
|
|
|
|
|
{
|
|
|
|
|
return (T)DependencyResolver.Current.GetService(typeof(T));
|
|
|
|
|
}
|
2015-10-26 21:58:12 +08:00
|
|
|
|
}
|
|
|
|
|
}
|