Skip to content

Commit

Permalink
Fix IOC
Browse files Browse the repository at this point in the history
  • Loading branch information
farajfarook committed Apr 15, 2019
1 parent 7cdfd9c commit 85b1cec
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
@@ -1,6 +1,6 @@
env:
global:
- PACKAGE_VERSION="1.1.24"
- PACKAGE_VERSION="1.1.25"
- PACKAGE_ICON="https://www.enbiso.com/logo.svg"
- PACKAGE_PROJECT="https://nlib.enbiso.com"
- PACKAGE_REPO="https://github.com/enbiso/Enbiso.NLib"
Expand Down
10 changes: 3 additions & 7 deletions Enbiso.NLib.Cqrs.Idempotent/ServiceExtensions.cs
Expand Up @@ -8,19 +8,15 @@ public static class ServiceExtensions
{
public static IServiceCollection AddCqrsIdempotent(this IServiceCollection services, bool autoLoadHandlers = true)
{
if(autoLoadHandlers) return services.AddCqrsIdempotent(Assembly.GetCallingAssembly());

services.AddIdempotency();
services.AddCqrs();
services.AddScoped<IIdempotentCommandBus, IdempotentCommandBus>();
return services;
if (autoLoadHandlers) return services.AddCqrsIdempotent(Assembly.GetCallingAssembly());
return services.AddCqrsIdempotent(new Assembly[0]);
}

public static IServiceCollection AddCqrsIdempotent(this IServiceCollection services,
params Assembly[] assemblies)
{
services.AddIdempotency();
services.AddCqrs(assemblies);
services.AddCqrs(assemblies);
services.AddScoped<IIdempotentCommandBus, IdempotentCommandBus>();
return services;
}
Expand Down
10 changes: 4 additions & 6 deletions Enbiso.NLib.Cqrs/ServiceExtensions.cs
Expand Up @@ -10,21 +10,19 @@ public static class ServiceExtensions
{
public static IServiceCollection AddCqrs(this IServiceCollection services, bool autoLoadHandlers = true)
{
if(!autoLoadHandlers) return services.AddCqrs();

var assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => !a.IsDynamic);
return services.AddCqrs(assembly);
if (!autoLoadHandlers) return services.AddCqrs(new Assembly[0]);
return services.AddCqrs(Assembly.GetCallingAssembly());
}

public static IServiceCollection AddCqrs(this IServiceCollection services, params Assembly[] assemblies)
{
if (services.All(s => s.ServiceType != typeof(IMediator)))
services.AddMediatR(assemblies);

services.AddScoped<ICommandBus, CommandBus>();
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(LoggingBehavior<,>));
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidatorBehavior<,>));
return services;
}
}
}
}

0 comments on commit 85b1cec

Please sign in to comment.