统一注入代码

This commit is contained in:
yubao
2017-12-08 05:49:00 +08:00
parent 38cb16d9e7
commit 89d646bb04
18 changed files with 214 additions and 272 deletions

View File

@@ -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>

View File

@@ -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>();
}
}
}

View File

@@ -118,7 +118,6 @@
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="AutofacExt.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TestBase.cs" />
<Compile Include="TestFunction.cs" />

View File

@@ -1,10 +1,12 @@
namespace OpenAuth.UnitTest
using OpenAuth.App;
namespace OpenAuth.UnitTest
{
public class TestBase
{
public TestBase()
{
AutofacExt.InitDI();
AutofacExt.InitAutofac();
}
}
}

View File

@@ -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,