This commit is contained in:
454313500@qq.com
2021-03-21 02:13:08 +08:00
parent 367f8f8830
commit 1ecb92df33
7 changed files with 49 additions and 4 deletions

View File

@@ -5,6 +5,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Autofac" Version="6.1.0" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

View File

@@ -1,3 +1,4 @@
using Autofac.Extensions.DependencyInjection;
using CC.Yi.DAL;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
@@ -38,6 +39,6 @@ namespace CC.Yi.API
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}).UseServiceProviderFactory(new AutofacServiceProviderFactory());
}
}

View File

@@ -1,5 +1,8 @@
using Autofac;
using Autofac.Extras.DynamicProxy;
using CC.Yi.BLL;
using CC.Yi.Common.Castle;
using CC.Yi.DAL;
using CC.Yi.IBLL;
using CC.Yi.IDAL;
@@ -45,8 +48,18 @@ namespace CC.Yi.API
{
options.UseSqlServer(connection, b => b.MigrationsAssembly("CC.Yi.API"));//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>
});
services.AddScoped(typeof(IBaseDal<>), typeof(BaseDal<>));
services.AddScoped(typeof(IstudentBll), typeof(studentBll));
//<2F><><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>ת<EFBFBD><D7AA><EFBFBD><EFBFBD>Autofac
//services.AddScoped(typeof(IBaseDal<>), typeof(BaseDal<>));
//services.AddScoped(typeof(IstudentBll), typeof(studentBll));
}
//<2F><>̬ <20><><EFBFBD><EFBFBD>AOP˼<50><CBBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2> Autofac
public void ConfigureContainer(ContainerBuilder builder)
{
builder.RegisterType(typeof(CustomAutofacAop));
builder.RegisterGeneric(typeof(BaseDal<>)).As(typeof(IBaseDal<>)) ;
builder.RegisterType<studentBll>().As<IstudentBll>().EnableInterfaceInterceptors();//<2F><>ʾע<CABE><D7A2>ǰ<EFBFBD><C7B0>Ҫִ<D2AA><D6B4>Castle
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

View File

@@ -5,6 +5,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Autofac.Extras.DynamicProxy" Version="6.0.0" />
<PackageReference Include="Castle.Core" Version="4.4.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>

View File

@@ -0,0 +1,23 @@
using Castle.DynamicProxy;
using System;
using System.Collections.Generic;
using System.Text;
namespace CC.Yi.Common.Castle
{
public class CustomAutofacAop : IInterceptor
{
public void Intercept(IInvocation invocation)
{
{
//这里写执行方法前
}
invocation.Proceed();//执行具体的实例
{
//这里写执行方法后
}
}
}
}

View File

@@ -6,6 +6,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\CC.Yi.Common\CC.Yi.Common.csproj" />
<ProjectReference Include="..\CC.Yi.Model\CC.Yi.Model.csproj" />
</ItemGroup>

View File

@@ -1,10 +1,13 @@
using System;
using Autofac.Extras.DynamicProxy;
using CC.Yi.Common.Castle;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
namespace CC.Yi.IBLL
{
[Intercept(typeof(CustomAutofacAop))]
public interface IBaseBll<T> where T : class, new()
{
#region