mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-11-09 02:44:44 +08:00
统一注入代码
This commit is contained in:
@@ -1,70 +0,0 @@
|
||||
// ***********************************************************************
|
||||
// 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扩展</summary>
|
||||
// ***********************************************************************
|
||||
|
||||
using Autofac;
|
||||
using Autofac.Integration.Mvc;
|
||||
using OpenAuth.App;
|
||||
using System.Reflection;
|
||||
using System.Web.Mvc;
|
||||
using OpenAuth.Repository;
|
||||
using OpenAuth.Repository.Interface;
|
||||
|
||||
namespace OpenAuth.Mvc
|
||||
{
|
||||
public static class AutofacExt
|
||||
{
|
||||
private static IContainer _container;
|
||||
|
||||
public static void InitAutofac()
|
||||
{
|
||||
var builder = new ContainerBuilder();
|
||||
|
||||
//注册数据库基础操作和工作单元
|
||||
builder.RegisterGeneric(typeof(BaseRepository<>)).As(typeof(IRepository<>)).PropertiesAutowired();
|
||||
builder.RegisterType(typeof(UnitWork)).As(typeof(IUnitWork)).PropertiesAutowired();
|
||||
|
||||
//注册app层
|
||||
builder.RegisterAssemblyTypes(Assembly.GetAssembly(typeof (UserManagerApp))).PropertiesAutowired();
|
||||
|
||||
// 注册controller,使用属性注入
|
||||
builder.RegisterControllers(Assembly.GetExecutingAssembly()).PropertiesAutowired();
|
||||
|
||||
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());
|
||||
|
||||
// 注册所有的Attribute
|
||||
builder.RegisterFilterProvider();
|
||||
|
||||
// Set the dependency resolver to be Autofac.
|
||||
_container = builder.Build();
|
||||
DependencyResolver.SetResolver(new AutofacDependencyResolver(_container));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从容器中获取对象
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public static T GetFromFac<T>()
|
||||
{
|
||||
return _container.Resolve<T>();
|
||||
// return (T)DependencyResolver.Current.GetService(typeof(T));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,11 +40,11 @@ namespace OpenAuth.Mvc.Controllers
|
||||
|
||||
//添加组织提交
|
||||
[HttpPost]
|
||||
public string AddOrUpdate(Org org)
|
||||
public string Add(Org org)
|
||||
{
|
||||
try
|
||||
{
|
||||
OrgApp.AddOrUpdate(org);
|
||||
OrgApp.Add(org);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -53,7 +53,23 @@ namespace OpenAuth.Mvc.Controllers
|
||||
}
|
||||
return JsonHelper.Instance.Serialize(Result);
|
||||
}
|
||||
|
||||
|
||||
//编辑
|
||||
[HttpPost]
|
||||
public string Update(Org org)
|
||||
{
|
||||
try
|
||||
{
|
||||
OrgApp.Update(org);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Result.Code = 500;
|
||||
Result.Message = ex.Message;
|
||||
}
|
||||
return JsonHelper.Instance.Serialize(Result);
|
||||
}
|
||||
|
||||
public string LoadChildren(string id)
|
||||
{
|
||||
return JsonHelper.Instance.Serialize(OrgApp.LoadAllChildren(id));
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
using System;
|
||||
using System.Web;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Optimization;
|
||||
using System.Web.Routing;
|
||||
using Infrastructure;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using OpenAuth.Mvc.Controllers;
|
||||
using OpenAuth.App;
|
||||
using OpenAuth.Mvc.Models;
|
||||
|
||||
namespace OpenAuth.Mvc
|
||||
|
||||
@@ -146,7 +146,6 @@
|
||||
<Compile Include="Areas\FlowManage\Controllers\FormDesignController.cs" />
|
||||
<Compile Include="Areas\FlowManage\Controllers\FlowDesignController.cs" />
|
||||
<Compile Include="Areas\FlowManage\FlowManageAreaRegistration.cs" />
|
||||
<Compile Include="AutofacExt.cs" />
|
||||
<Compile Include="Controllers\BaseController.cs" />
|
||||
<Compile Include="Controllers\CategoriesController.cs" />
|
||||
<Compile Include="Controllers\ErrorController.cs" />
|
||||
@@ -373,7 +372,6 @@
|
||||
<Content Include="Views\Categories\Index.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="App_Data\" />
|
||||
<Folder Include="Areas\FlowManage\Models\" />
|
||||
<Folder Include="Areas\FlowManage\Views\Shared\" />
|
||||
<Folder Include="Views\Base\" />
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
<sessionState mode="InProc" timeout="60" />
|
||||
</system.web>
|
||||
<system.webServer>
|
||||
<modules runAllManagedModulesForAllRequests="true" >
|
||||
<modules runAllManagedModulesForAllRequests="true">
|
||||
<remove name="FormsAuthenticationModule" />
|
||||
</modules>
|
||||
<handlers>
|
||||
@@ -103,6 +103,14 @@
|
||||
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
<entityFramework>
|
||||
|
||||
Reference in New Issue
Block a user