Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 941fd85

Browse files
Transaction Behaviour moved to infra layer
1 parent b21f0b6 commit 941fd85

File tree

4 files changed

+30
-16
lines changed

4 files changed

+30
-16
lines changed

‎src/AspnetRun.Api/IoC/DependencyRegistrar.cs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
using AspnetRun.Api.Application.Behaviors;
1+
using AspnetRun.Api.Application.Commands;
22
using AspnetRun.Api.Application.Validations;
3-
using AspnetRun.Api.Requests;
43
using AspnetRun.Infrastructure.IoC;
54
using AspnetRun.Infrastructure.Misc;
65
using Autofac;
@@ -14,22 +13,10 @@ public class DependencyRegistrar : IDependencyRegistrar
1413
{
1514
public void Register(ContainerBuilder builder, ITypeFinder typeFinder)
1615
{
17-
builder.RegisterAssemblyTypes(typeof(IMediator).GetTypeInfo().Assembly)
18-
.AsImplementedInterfaces();
19-
2016
// Register all the Command classes (they implement IRequestHandler) in assembly holding the Commands
21-
builder.RegisterAssemblyTypes(typeof(CreateProductRequest).GetTypeInfo().Assembly)
17+
builder.RegisterAssemblyTypes(typeof(CreateProductCommandHandler).GetTypeInfo().Assembly)
2218
.AsClosedTypesOf(typeof(IRequestHandler<,>));
2319

24-
builder.Register<ServiceFactory>(context =>
25-
{
26-
var componentContext = context.Resolve<IComponentContext>();
27-
return t => { object o; return componentContext.TryResolve(t, out o) ? o : null; };
28-
});
29-
30-
builder.RegisterGeneric(typeof(TransactionBehaviour<,>)).As(typeof(IPipelineBehavior<,>));
31-
32-
3320
// Register the Command's Validators (Validators based on FluentValidation library)
3421
builder.RegisterAssemblyTypes(typeof(CreateProductRequestValidator).GetTypeInfo().Assembly)
3522
.Where(t => t.IsClosedTypeOf(typeof(IValidator<>)))

‎src/AspnetRun.Infrastructure/AspnetRun.Infrastructure.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
<ItemGroup>
88
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.4.0" />
9+
<PackageReference Include="MediatR" Version="7.0.0" />
910
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.0" />
1011
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.4" />
1112
<PackageReference Include="System.IO.FileSystem.AccessControl" Version="4.5.0" />

‎src/AspnetRun.Api/Application/Behaviors/TransactionBehaviour.cs renamed to ‎src/AspnetRun.Infrastructure/Behaviors/TransactionBehaviour.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using System.Threading;
77
using System.Threading.Tasks;
88

9-
namespace AspnetRun.Api.Application.Behaviors
9+
namespace AspnetRun.Infrastructure.Behaviors
1010
{
1111
public class TransactionBehaviour<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
1212
{

‎src/AspnetRun.Infrastructure/IoC/DependencyRegistrar.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
using AspnetRun.Core.Interfaces;
22
using AspnetRun.Core.Repositories;
33
using AspnetRun.Core.Repositories.Base;
4+
using AspnetRun.Infrastructure.Behaviors;
45
using AspnetRun.Infrastructure.Data;
56
using AspnetRun.Infrastructure.Logging;
67
using AspnetRun.Infrastructure.Misc;
78
using AspnetRun.Infrastructure.Repository;
89
using AspnetRun.Infrastructure.Repository.Base;
910
using Autofac;
11+
using MediatR;
12+
using System.Reflection;
1013

1114
namespace AspnetRun.Infrastructure.IoC
1215
{
@@ -23,6 +26,29 @@ public void Register(ContainerBuilder builder, ITypeFinder typeFinder)
2326
builder.RegisterGeneric(typeof(LoggerAdapter<>)).As(typeof(IAppLogger<>)).InstancePerDependency();
2427

2528
builder.RegisterType<AspnetRunContextSeed>();
29+
30+
builder.RegisterAssemblyTypes(typeof(IMediator).GetTypeInfo().Assembly)
31+
.AsImplementedInterfaces();
32+
33+
// Register all the Command classes (they implement IRequestHandler) in assembly holding the Commands
34+
//var handlerAssemblies = typeFinder.FindClassesOfType(typeof(IRequestHandler<,>))
35+
// .Select(t => t.Assembly).Distinct().ToArray();
36+
//builder.RegisterAssemblyTypes(handlerAssemblies)
37+
// .AsClosedTypesOf(typeof(IRequestHandler<,>));
38+
39+
builder.Register<ServiceFactory>(context =>
40+
{
41+
var componentContext = context.Resolve<IComponentContext>();
42+
return t => { object o; return componentContext.TryResolve(t, out o) ? o : null; };
43+
});
44+
45+
builder.RegisterGeneric(typeof(TransactionBehaviour<,>)).As(typeof(IPipelineBehavior<,>));
46+
47+
//// Register the Command's Validators (Validators based on FluentValidation library)
48+
//var validatorAssemblies = typeFinder.FindClassesOfType(typeof(IValidator<,>))
49+
// .Select(t => t.Assembly).Distinct().ToArray();
50+
//builder.RegisterAssemblyTypes(validatorAssemblies).
51+
// Where(t => t.IsClosedTypeOf(typeof(IValidator<>))).AsImplementedInterfaces();
2652
}
2753

2854
public int Order => 1;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /