mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-08-23 22:11:35 +08:00
统一注入代码
This commit is contained in:
parent
38cb16d9e7
commit
89d646bb04
@ -12,15 +12,17 @@
|
||||
// <summary>IOC扩展</summary>
|
||||
// ***********************************************************************
|
||||
|
||||
using System.Reflection;
|
||||
using System.Web.Http;
|
||||
using System.Web.Mvc;
|
||||
using Autofac;
|
||||
using Autofac.Integration.Mvc;
|
||||
using OpenAuth.App;
|
||||
using System.Reflection;
|
||||
using System.Web.Mvc;
|
||||
using Autofac.Integration.WebApi;
|
||||
using OpenAuth.Repository;
|
||||
using OpenAuth.Repository.Interface;
|
||||
using IContainer = Autofac.IContainer;
|
||||
|
||||
namespace OpenAuth.Mvc
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public static class AutofacExt
|
||||
{
|
||||
@ -35,12 +37,15 @@ namespace OpenAuth.Mvc
|
||||
builder.RegisterType(typeof(UnitWork)).As(typeof(IUnitWork)).PropertiesAutowired();
|
||||
|
||||
//注册app层
|
||||
builder.RegisterAssemblyTypes(Assembly.GetAssembly(typeof (UserManagerApp))).PropertiesAutowired();
|
||||
builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly()).PropertiesAutowired();
|
||||
|
||||
// 注册controller,使用属性注入
|
||||
builder.RegisterControllers(Assembly.GetExecutingAssembly()).PropertiesAutowired();
|
||||
builder.RegisterControllers(Assembly.GetCallingAssembly()).PropertiesAutowired();
|
||||
|
||||
builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
|
||||
//注册所有的ApiControllers
|
||||
builder.RegisterApiControllers(Assembly.GetCallingAssembly()).PropertiesAutowired();
|
||||
|
||||
builder.RegisterModelBinders(Assembly.GetCallingAssembly());
|
||||
builder.RegisterModelBinderProvider();
|
||||
|
||||
// OPTIONAL: Register web abstractions like HttpContextBase.
|
||||
@ -54,7 +59,12 @@ namespace OpenAuth.Mvc
|
||||
|
||||
// Set the dependency resolver to be Autofac.
|
||||
_container = builder.Build();
|
||||
|
||||
//Set the MVC DependencyResolver
|
||||
DependencyResolver.SetResolver(new AutofacDependencyResolver(_container));
|
||||
|
||||
//Set the WebApi DependencyResolver
|
||||
GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver((IContainer)_container);
|
||||
}
|
||||
|
||||
/// <summary>
|
@ -33,6 +33,18 @@
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Autofac, Version=3.5.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Autofac.3.5.2\lib\net40\Autofac.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Autofac.Integration.Mvc, Version=3.3.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Autofac.Mvc5.3.3.4\lib\net45\Autofac.Integration.Mvc.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Autofac.Integration.WebApi, Version=3.4.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Autofac.WebApi2.3.4.0\lib\net45\Autofac.Integration.WebApi.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
@ -41,18 +53,27 @@
|
||||
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="OptimaJet.Workflow.Core, Version=1.5.5.0, Culture=neutral, PublicKeyToken=3d29392dccd464d7, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\WorkflowEngine.NET-Core.1.5.5.2\lib\net45\OptimaJet.Workflow.Core.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Web.Helpers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.Helpers.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Http.WebHost, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.3\lib\net45\System.Web.Http.WebHost.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.Mvc.5.2.3\lib\net45\System.Web.Mvc.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
@ -81,6 +102,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AuthoriseService.cs" />
|
||||
<Compile Include="AutofacExt.cs" />
|
||||
<Compile Include="BaseApp.cs" />
|
||||
<Compile Include="AuthorizeApp.cs" />
|
||||
<Compile Include="CategoryApp.cs" />
|
||||
@ -111,7 +133,6 @@
|
||||
<Compile Include="UserManagerApp.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="OrgManagerApp.cs" />
|
||||
<Compile Include="Response\CommandModel.cs" />
|
||||
<Compile Include="Response\UserWithAccessedCtrls.cs" />
|
||||
<Compile Include="Response\ModuleElementVM.cs" />
|
||||
<Compile Include="Response\ModuleView.cs" />
|
||||
|
@ -7,39 +7,41 @@ using OpenAuth.Repository.Interface;
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public class OrgManagerApp
|
||||
public class OrgManagerApp : BaseApp<Org>
|
||||
{
|
||||
public IUnitWork _unitWork { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 添加部门
|
||||
/// </summary>
|
||||
/// <param name="org">The org.</param>
|
||||
/// <returns>System.Int32.</returns>
|
||||
/// <exception cref="System.Exception">未能找到该组织的父节点信息</exception>
|
||||
public string AddOrUpdate(Org org)
|
||||
public string Add(Org org)
|
||||
{
|
||||
ChangeModuleCascade(org);
|
||||
if (org.Id == string.Empty)
|
||||
{
|
||||
_unitWork.Add(org);
|
||||
|
||||
Repository.Add(org);
|
||||
|
||||
return org.Id;
|
||||
}
|
||||
else
|
||||
|
||||
public string Update(Org org)
|
||||
{
|
||||
ChangeModuleCascade(org);
|
||||
|
||||
//获取旧的的CascadeId
|
||||
var CascadeId = _unitWork.FindSingle<Org>(o => o.Id == org.Id).CascadeId;
|
||||
var cascadeId = Repository.FindSingle(o => o.Id == org.Id).CascadeId;
|
||||
//根据CascadeId查询子部门
|
||||
var orgs = _unitWork.Find<Org>(u => u.CascadeId.Contains(CascadeId) && u.Id != org.Id).OrderBy(u => u.CascadeId).ToList();
|
||||
var orgs = Repository.Find(u => u.CascadeId.Contains(cascadeId) && u.Id != org.Id)
|
||||
.OrderBy(u => u.CascadeId).ToList();
|
||||
|
||||
//更新操作
|
||||
_unitWork.Update(org);
|
||||
UnitWork.Update(org);
|
||||
|
||||
//更新子部门的CascadeId
|
||||
foreach (var a in orgs)
|
||||
{
|
||||
ChangeModuleCascade(a);
|
||||
_unitWork.Update(a);
|
||||
}
|
||||
UnitWork.Update(a);
|
||||
}
|
||||
|
||||
return org.Id;
|
||||
@ -50,10 +52,10 @@ namespace OpenAuth.App
|
||||
/// </summary>
|
||||
public void DelOrg(string[] ids)
|
||||
{
|
||||
var delOrg = _unitWork.Find<Org>(u => ids.Contains(u.Id)).ToList();
|
||||
var delOrg = Repository.Find(u => ids.Contains(u.Id)).ToList();
|
||||
foreach (var org in delOrg)
|
||||
{
|
||||
_unitWork.Delete<Org>(u => u.CascadeId.Contains(org.CascadeId));
|
||||
Repository.Delete(u => u.CascadeId.Contains(org.CascadeId));
|
||||
}
|
||||
}
|
||||
|
||||
@ -67,17 +69,17 @@ namespace OpenAuth.App
|
||||
{
|
||||
//用户角色
|
||||
var userRoleIds =
|
||||
_unitWork.Find<Relevance>(u => u.FirstId == userId && u.Key == "UserRole").Select(u => u.SecondId).ToList();
|
||||
UnitWork.Find<Relevance>(u => u.FirstId == userId && u.Key == "UserRole").Select(u => u.SecondId).ToList();
|
||||
|
||||
//用户角色与自己分配到的角色ID
|
||||
var moduleIds =
|
||||
_unitWork.Find<Relevance>(
|
||||
UnitWork.Find<Relevance>(
|
||||
u =>
|
||||
(u.FirstId == userId && u.Key == "UserOrg") ||
|
||||
(u.Key == "RoleOrg" && userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId).ToList();
|
||||
|
||||
if (!moduleIds.Any()) return new List<Org>();
|
||||
return _unitWork.Find<Org>(u => moduleIds.Contains(u.Id)).ToList();
|
||||
return UnitWork.Find<Org>(u => moduleIds.Contains(u.Id)).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -87,11 +89,11 @@ namespace OpenAuth.App
|
||||
public List<Org> LoadForRole(string roleId)
|
||||
{
|
||||
var moduleIds =
|
||||
_unitWork.Find<Relevance>(u => u.FirstId == roleId && u.Key == "RoleOrg")
|
||||
UnitWork.Find<Relevance>(u => u.FirstId == roleId && u.Key == "RoleOrg")
|
||||
.Select(u => u.SecondId)
|
||||
.ToList();
|
||||
if (!moduleIds.Any()) return new List<Org>();
|
||||
return _unitWork.Find<Org>(u => moduleIds.Contains(u.Id)).ToList();
|
||||
return UnitWork.Find<Org>(u => moduleIds.Contains(u.Id)).ToList();
|
||||
}
|
||||
|
||||
|
||||
@ -114,13 +116,13 @@ namespace OpenAuth.App
|
||||
string cascadeId = "0.";
|
||||
if (!string.IsNullOrEmpty(orgId))
|
||||
{
|
||||
var org = _unitWork.FindSingle<Org>(u => u.Id == orgId);
|
||||
var org = UnitWork.FindSingle<Org>(u => u.Id == orgId);
|
||||
if (org == null)
|
||||
throw new Exception("未能找到指定对象信息");
|
||||
cascadeId = org.CascadeId;
|
||||
}
|
||||
|
||||
return _unitWork.Find<Org>(u => u.CascadeId.Contains(cascadeId));
|
||||
return UnitWork.Find<Org>(u => u.CascadeId.Contains(cascadeId));
|
||||
}
|
||||
|
||||
#region 私有方法
|
||||
@ -130,19 +132,19 @@ namespace OpenAuth.App
|
||||
{
|
||||
string cascadeId;
|
||||
int currentCascadeId = 1; //当前结点的级联节点最后一位
|
||||
var sameLevels = _unitWork.Find<Org>(o => o.ParentId == org.ParentId && o.Id != org.Id);
|
||||
var sameLevels = UnitWork.Find<Org>(o => o.ParentId == org.ParentId && o.Id != org.Id);
|
||||
foreach (var obj in sameLevels)
|
||||
{
|
||||
int objCascadeId = int.Parse(obj.CascadeId.TrimEnd('.').Split('.').Last());
|
||||
if (currentCascadeId <= objCascadeId) currentCascadeId = objCascadeId + 1;
|
||||
}
|
||||
|
||||
if (org.ParentId != null && org.ParentId != string.Empty)
|
||||
if (!string.IsNullOrEmpty(org.ParentId))
|
||||
{
|
||||
var parentOrg = _unitWork.FindSingle<Org>(o => o.Id == org.ParentId);
|
||||
var parentOrg = UnitWork.FindSingle<Org>(o => o.Id == org.ParentId);
|
||||
if (parentOrg != null)
|
||||
{
|
||||
cascadeId = parentOrg.CascadeId + currentCascadeId+".";
|
||||
cascadeId = parentOrg.CascadeId + currentCascadeId + ".";
|
||||
org.ParentName = parentOrg.Name;
|
||||
}
|
||||
else
|
||||
@ -152,7 +154,7 @@ namespace OpenAuth.App
|
||||
}
|
||||
else
|
||||
{
|
||||
cascadeId = ".0." + currentCascadeId+".";
|
||||
cascadeId = ".0." + currentCascadeId + ".";
|
||||
org.ParentName = "根节点";
|
||||
}
|
||||
|
||||
|
@ -1,25 +0,0 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : OpenAuth.App
|
||||
// Author : yubaolee
|
||||
// Created : 09-05-2016
|
||||
//
|
||||
// Last Modified By : yubaolee
|
||||
// Last Modified On : 09-05-2016
|
||||
// Contact : Microsoft
|
||||
// File: CommandModel.cs
|
||||
// ***********************************************************************
|
||||
|
||||
using OptimaJet.Workflow.Core.Model;
|
||||
|
||||
namespace OpenAuth.App.Response
|
||||
{
|
||||
/// <summary>
|
||||
/// workflow命令
|
||||
/// </summary>
|
||||
public class CommandModel
|
||||
{
|
||||
public string Key { get; set; }
|
||||
public string Value { get; set; }
|
||||
public TransitionClassifier Classifier { get; set; }
|
||||
}
|
||||
}
|
@ -1,9 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Autofac" version="3.5.2" targetFramework="net45" />
|
||||
<package id="Autofac.Mvc5" version="3.3.4" targetFramework="net45" />
|
||||
<package id="Autofac.WebApi2" version="3.4.0" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.3" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net45" />
|
||||
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
|
||||
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
|
||||
<package id="WorkflowEngine.NET-Core" version="1.5.5.2" targetFramework="net45" />
|
||||
</packages>
|
@ -40,11 +40,27 @@ 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)
|
||||
{
|
||||
Result.Code = 500;
|
||||
Result.Message = ex.Message;
|
||||
}
|
||||
return JsonHelper.Instance.Serialize(Result);
|
||||
}
|
||||
|
||||
//编辑
|
||||
[HttpPost]
|
||||
public string Update(Org org)
|
||||
{
|
||||
try
|
||||
{
|
||||
OrgApp.Update(org);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -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>
|
||||
|
@ -72,6 +72,14 @@
|
||||
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
|
||||
</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>
|
||||
</configuration>
|
||||
|
@ -1,35 +0,0 @@
|
||||
using System.Reflection;
|
||||
using System.Web.Mvc;
|
||||
using Autofac;
|
||||
using Autofac.Integration.Mvc;
|
||||
using OpenAuth.App;
|
||||
using OpenAuth.Repository;
|
||||
using OpenAuth.Repository.Interface;
|
||||
|
||||
namespace OpenAuth.UnitTest
|
||||
{
|
||||
public class AutofacExt
|
||||
{
|
||||
private static IContainer _container;
|
||||
|
||||
public static void InitDI()
|
||||
{
|
||||
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();
|
||||
|
||||
_container = builder.Build();
|
||||
DependencyResolver.SetResolver(new AutofacDependencyResolver(_container));
|
||||
}
|
||||
|
||||
public static T GetFromFac<T>()
|
||||
{
|
||||
return _container.Resolve<T>();
|
||||
}
|
||||
}
|
||||
}
|
@ -118,7 +118,6 @@
|
||||
</Otherwise>
|
||||
</Choose>
|
||||
<ItemGroup>
|
||||
<Compile Include="AutofacExt.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="TestBase.cs" />
|
||||
<Compile Include="TestFunction.cs" />
|
||||
|
@ -1,10 +1,12 @@
|
||||
namespace OpenAuth.UnitTest
|
||||
using OpenAuth.App;
|
||||
|
||||
namespace OpenAuth.UnitTest
|
||||
{
|
||||
public class TestBase
|
||||
{
|
||||
public TestBase()
|
||||
{
|
||||
AutofacExt.InitDI();
|
||||
AutofacExt.InitAutofac();
|
||||
}
|
||||
}
|
||||
}
|
@ -25,7 +25,7 @@ namespace OpenAuth.UnitTest
|
||||
{
|
||||
var random = new Random();
|
||||
int val = random.Next();
|
||||
_app.AddOrUpdate(new Org
|
||||
_app.Add(new Org
|
||||
{
|
||||
Id = string.Empty,
|
||||
Name = "test" + val,
|
||||
|
@ -1,73 +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 System.Reflection;
|
||||
using System.Web.Http;
|
||||
using System.Web.Mvc;
|
||||
using Autofac;
|
||||
using Autofac.Integration.Mvc;
|
||||
using Autofac.Integration.WebApi;
|
||||
using OpenAuth.App;
|
||||
using OpenAuth.Repository;
|
||||
using OpenAuth.Repository.Interface;
|
||||
|
||||
namespace OpenAuth.WebApi
|
||||
{
|
||||
internal static class AutofacExt
|
||||
{
|
||||
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 (AuthorizeApp))).PropertiesAutowired();
|
||||
|
||||
|
||||
// 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();
|
||||
|
||||
//注册所有的ApiControllers
|
||||
builder.RegisterApiControllers(Assembly.GetExecutingAssembly()).PropertiesAutowired();
|
||||
|
||||
var container = builder.Build();
|
||||
HttpConfiguration config = GlobalConfiguration.Configuration;
|
||||
//注册api容器需要使用HttpConfiguration对象
|
||||
config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
|
||||
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从容器中获取对象
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public static T GetFromFac<T>()
|
||||
{
|
||||
return (T)DependencyResolver.Current.GetService(typeof(T));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
using System.Web.Http;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Optimization;
|
||||
using System.Web.Routing;
|
||||
using OpenAuth.App;
|
||||
|
||||
namespace OpenAuth.WebApi
|
||||
{
|
||||
|
@ -178,7 +178,6 @@
|
||||
<Compile Include="Areas\SSO\Controllers\LoginController.cs" />
|
||||
<Compile Include="Areas\SSO\Controllers\CheckController.cs" />
|
||||
<Compile Include="Areas\SSO\SSOAreaRegistration.cs" />
|
||||
<Compile Include="AutofacExt.cs" />
|
||||
<Compile Include="Global.asax.cs">
|
||||
<DependentUpon>Global.asax</DependentUpon>
|
||||
</Compile>
|
||||
|
@ -45,12 +45,24 @@
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
|
||||
<bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Autofac" publicKeyToken="17863af14b0044da" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-3.5.0.0" newVersion="3.5.0.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>
|
||||
<system.codedom>
|
||||
|
Loading…
Reference in New Issue
Block a user