2015-09-23 00:10:11 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Web;
|
|
|
|
|
using System.Web.Mvc;
|
|
|
|
|
using System.Web.Optimization;
|
|
|
|
|
using System.Web.Routing;
|
|
|
|
|
using Autofac;
|
|
|
|
|
using Autofac.Integration.Mvc;
|
|
|
|
|
using OpenAuth.App;
|
|
|
|
|
using OpenAuth.Domain.Interface;
|
|
|
|
|
using OpenAuth.Repository;
|
|
|
|
|
|
|
|
|
|
namespace OpenAuth.Mvc
|
|
|
|
|
{
|
|
|
|
|
public class MvcApplication : System.Web.HttpApplication
|
|
|
|
|
{
|
|
|
|
|
protected void Application_Start()
|
|
|
|
|
{
|
|
|
|
|
InitAutofac();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AreaRegistration.RegisterAllAreas();
|
|
|
|
|
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
|
|
|
|
|
RouteConfig.RegisterRoutes(RouteTable.Routes);
|
|
|
|
|
BundleConfig.RegisterBundles(BundleTable.Bundles);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void InitAutofac()
|
|
|
|
|
{
|
|
|
|
|
var builder = new ContainerBuilder();
|
|
|
|
|
|
|
|
|
|
builder.RegisterType<UserRepository>().As<IUserRepository>();
|
|
|
|
|
builder.RegisterType<LoginApp>();
|
|
|
|
|
|
|
|
|
|
// Register your MVC controllers.
|
|
|
|
|
builder.RegisterControllers(typeof (MvcApplication).Assembly);
|
|
|
|
|
|
|
|
|
|
// 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));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|