This commit is contained in:
yubao 2017-11-29 00:48:51 +08:00
parent ead70c2f56
commit c860101747
6 changed files with 32 additions and 60 deletions

View File

@ -1,28 +0,0 @@
using OpenAuth.Domain.Interface;
namespace OpenAuth.Domain.Service
{
/// <summary>
/// 权限分配工厂,根据是否是开发者账号创建
/// </summary>
public class AuthoriseFactory
{
public IUnitWork _unitWork { get; set; }
public AuthoriseService Create(string loginuser)
{
if (loginuser == "System")
{
return new SystemAuthService();
}
else
{
return new AuthoriseService()
{
_unitWork = _unitWork,
User = _unitWork.FindSingle<User>(u =>u.Account == loginuser)
};
}
}
}
}

View File

@ -1,6 +1,8 @@
using System.Linq;
using Infrastructure;
using OpenAuth.App.ViewModel;
using OpenAuth.Domain;
using OpenAuth.Domain.Interface;
using OpenAuth.Domain.Service;
namespace OpenAuth.App
@ -11,16 +13,26 @@ namespace OpenAuth.App
/// </summary>
public class AuthorizeApp
{
private readonly AuthoriseFactory _factory;
public SystemAuthService AuthService { get; set; }
public AuthoriseService AuthoriseService { get; set; }
public AuthorizeApp(AuthoriseFactory service)
public IUnitWork _unitWork { get; set; }
public AuthoriseService Create(string loginuser)
{
_factory = service;
if (loginuser == "System")
{
return AuthService;
}
else
{
AuthoriseService.User = _unitWork.FindSingle<User>(u => u.Account == loginuser);
return AuthoriseService;
}
}
public UserWithAccessedCtrls GetAccessedControls(string username)
{
var service = _factory.Create(username);
var service = Create(username);
var user = new UserWithAccessedCtrls
{
User = service.User,

View File

@ -80,7 +80,6 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AuthoriseFactory.cs" />
<Compile Include="AuthoriseService.cs" />
<Compile Include="CategoryManagerApp.cs" />
<Compile Include="AuthorizeApp.cs" />

View File

@ -13,13 +13,11 @@
// ***********************************************************************
using Autofac;
using Autofac.Configuration;
using Autofac.Integration.Mvc;
using OpenAuth.App;
using System.Reflection;
using System.Web.Mvc;
using OpenAuth.Domain.Interface;
using OpenAuth.Domain.Service;
using OpenAuth.Repository;
namespace OpenAuth.Mvc
@ -33,20 +31,11 @@ namespace OpenAuth.Mvc
var builder = new ContainerBuilder();
//注册数据库基础操作和工作单元
builder.RegisterGeneric(typeof(BaseRepository<>)).As(typeof(IRepository<>));
builder.RegisterType(typeof (UnitWork)).As(typeof (IUnitWork));
builder.RegisterGeneric(typeof(BaseRepository<>)).As(typeof(IRepository<>)).PropertiesAutowired();
builder.RegisterType(typeof(UnitWork)).As(typeof(IUnitWork)).PropertiesAutowired();
//注册app层
builder.RegisterAssemblyTypes(Assembly.GetAssembly(typeof (UserManagerApp)));
//注册领域服务
builder.RegisterAssemblyTypes(Assembly.GetAssembly(typeof(AuthoriseService)))
.Where(u =>u.Namespace== "OpenAuth.Domain.Service"
|| u.Namespace == "OpenAuth.Domain.Interface");
//注册Repository
builder.RegisterAssemblyTypes(Assembly.GetAssembly(typeof(UserManagerApp)))
.AsImplementedInterfaces();
builder.RegisterAssemblyTypes(Assembly.GetAssembly(typeof (UserManagerApp))).PropertiesAutowired();
// 注册controller使用属性注入
builder.RegisterControllers(Assembly.GetExecutingAssembly()).PropertiesAutowired();

View File

@ -19,18 +19,11 @@ namespace OpenAuth.UnitTest
var builder = new ContainerBuilder();
//注册数据库基础操作和工作单元
builder.RegisterGeneric(typeof(BaseRepository<>)).As(typeof(IRepository<>));
builder.RegisterType(typeof(UnitWork)).As(typeof(IUnitWork));
//注册WebConfig中的配置
builder.RegisterModule(new ConfigurationSettingsReader("autofac"));
builder.RegisterGeneric(typeof(BaseRepository<>)).As(typeof(IRepository<>)).PropertiesAutowired();
builder.RegisterType(typeof(UnitWork)).As(typeof(IUnitWork)).PropertiesAutowired();
//注册app层
builder.RegisterAssemblyTypes(Assembly.GetAssembly(typeof(UserManagerApp)));
//注册领域服务
builder.RegisterAssemblyTypes(Assembly.GetAssembly(typeof(AuthoriseService)))
.Where(u => u.Namespace == "OpenAuth.Domain.Service");
builder.RegisterAssemblyTypes(Assembly.GetAssembly(typeof(UserManagerApp))).PropertiesAutowired();
_container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(_container));

View File

@ -3,6 +3,7 @@ using System.Diagnostics;
using System.Linq;
using Infrastructure;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenAuth.App;
using OpenAuth.Domain.Service;
using OpenAuth.Repository;
@ -12,13 +13,19 @@ namespace OpenAuth.UnitTest
/// 测试用户授权服务
/// </summary>
[TestClass]
public class TestAuthen
public class TestAuthen :TestBase
{
private AuthorizeApp app;
public TestAuthen()
{
app = AutofacExt.GetFromFac<AuthorizeApp>();
}
[TestMethod]
public void TestMethod1()
{
AuthoriseFactory factory = new AuthoriseFactory( );
var service= factory.Create("System");
var service= app.Create("System");
var modules = service.Modules;