Skip to content

Commit

Permalink
move AddMediator and AddValidatorsFromAssembly, source cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pwelter34 committed Apr 9, 2024
1 parent db321c1 commit 96c486e
Show file tree
Hide file tree
Showing 277 changed files with 104 additions and 848 deletions.
3 changes: 3 additions & 0 deletions MediatR.CommandQuery.sln
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
VisualStudioVersion = 17.0.31825.309
MinimumVisualStudioVersion = 15.0.26124.0
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{0EE0FE20-53A5-41C9-BBAE-B2EC1B3808F8}"
ProjectSection(SolutionItems) = preProject
test\Directory.Build.props = test\Directory.Build.props
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MediatR.CommandQuery.Tests", "test\MediatR.CommandQuery.Tests\MediatR.CommandQuery.Tests.csproj", "{22432F49-0412-4979-8C05-62768A48CA2E}"
EndProject
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
using Injectio.Attributes;

using MediatR.CommandQuery.EntityFrameworkCore;
using MediatR.CommandQuery;

using Microsoft.Extensions.DependencyInjection;

using Tracker.WebService.Data.Entities;
using Tracker.WebService.Domain.Mapping;

namespace Tracker.WebService.Domain;

public class DomainServiceRegistration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Injectio.Attributes;

using MediatR.CommandQuery.MongoDB;
using MediatR.CommandQuery;

using Microsoft.Extensions.DependencyInjection;

Expand Down
31 changes: 0 additions & 31 deletions src/MediatR.CommandQuery.Cosmos/DomainServiceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,6 @@ namespace MediatR.CommandQuery.Cosmos;

public static class DomainServiceExtensions
{
public static IServiceCollection AddMediator(this IServiceCollection services)
{
if (services is null)
throw new System.ArgumentNullException(nameof(services));

// Register MediatR
var serviceConfig = new MediatRServiceConfiguration();
ServiceRegistrar.AddRequiredServices(services, serviceConfig);

return services;
}

public static IServiceCollection AddValidatorsFromAssembly<T>(this IServiceCollection services)
{
if (services is null)
throw new System.ArgumentNullException(nameof(services));

// Register validators
var scanner = AssemblyScanner.FindValidatorsInAssemblyContaining<T>();
foreach (var scanResult in scanner)
{
//Register as interface
services.TryAdd(new ServiceDescriptor(scanResult.InterfaceType, scanResult.ValidatorType, ServiceLifetime.Singleton));
//Register as self
services.TryAdd(new ServiceDescriptor(scanResult.ValidatorType, scanResult.ValidatorType, ServiceLifetime.Singleton));
}

return services;
}


public static IServiceCollection AddEntityQueries<TRepository, TEntity, TReadModel>(this IServiceCollection services)
where TRepository : ICosmosRepository<TEntity>
where TEntity : class, IHaveIdentifier<string>, new()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using MediatR.CommandQuery.Extensions;
using MediatR.CommandQuery.Queries;
using MediatR.CommandQuery.Services;
using MediatR.NotificationPublishers;
using MediatR.Registration;

using Microsoft.EntityFrameworkCore;
Expand All @@ -17,37 +18,6 @@ namespace MediatR.CommandQuery.EntityFrameworkCore;

public static class DomainServiceExtensions
{
public static IServiceCollection AddMediator(this IServiceCollection services)
{
if (services is null)
throw new System.ArgumentNullException(nameof(services));

// Register MediatR
var serviceConfig = new MediatRServiceConfiguration();
ServiceRegistrar.AddRequiredServices(services, serviceConfig);

return services;
}

public static IServiceCollection AddValidatorsFromAssembly<T>(this IServiceCollection services)
{
if (services is null)
throw new System.ArgumentNullException(nameof(services));

// Register validators
var scanner = AssemblyScanner.FindValidatorsInAssemblyContaining<T>();
foreach (var scanResult in scanner)
{
//Register as interface
services.TryAdd(new ServiceDescriptor(scanResult.InterfaceType, scanResult.ValidatorType, ServiceLifetime.Singleton));
//Register as self
services.TryAdd(new ServiceDescriptor(scanResult.ValidatorType, scanResult.ValidatorType, ServiceLifetime.Singleton));
}

return services;
}


public static IServiceCollection AddEntityQueries<TContext, TEntity, TKey, TReadModel>(this IServiceCollection services)
where TContext : DbContext
where TEntity : class, IHaveIdentifier<TKey>, new()
Expand Down Expand Up @@ -111,7 +81,6 @@ public static IServiceCollection AddEntityQueryDistributedCache<TContext, TEntit
}



public static IServiceCollection AddEntityCommands<TContext, TEntity, TKey, TReadModel, TCreateModel, TUpdateModel>(this IServiceCollection services)
where TContext : DbContext
where TEntity : class, IHaveIdentifier<TKey>, new()
Expand Down
34 changes: 0 additions & 34 deletions src/MediatR.CommandQuery.MongoDB/DomainServiceExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
using FluentValidation;

using MediatR.CommandQuery.Behaviors;
using MediatR.CommandQuery.Commands;
using MediatR.CommandQuery.Definitions;
using MediatR.CommandQuery.Extensions;
using MediatR.CommandQuery.MongoDB.Handlers;
using MediatR.CommandQuery.Queries;
using MediatR.CommandQuery.Services;
using MediatR.Registration;

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
Expand All @@ -18,37 +15,6 @@ namespace MediatR.CommandQuery.MongoDB;

public static class DomainServiceExtensions
{
public static IServiceCollection AddMediator(this IServiceCollection services)
{
if (services is null)
throw new System.ArgumentNullException(nameof(services));

// Register MediatR
var serviceConfig = new MediatRServiceConfiguration();
ServiceRegistrar.AddRequiredServices(services, serviceConfig);

return services;
}

public static IServiceCollection AddValidatorsFromAssembly<T>(this IServiceCollection services)
{
if (services is null)
throw new System.ArgumentNullException(nameof(services));

// Register validators
var scanner = AssemblyScanner.FindValidatorsInAssemblyContaining<T>();
foreach (var scanResult in scanner)
{
//Register as interface
services.TryAdd(new ServiceDescriptor(scanResult.InterfaceType, scanResult.ValidatorType, ServiceLifetime.Singleton));
//Register as self
services.TryAdd(new ServiceDescriptor(scanResult.ValidatorType, scanResult.ValidatorType, ServiceLifetime.Singleton));
}

return services;
}


public static IServiceCollection AddEntityQueries<TRepository, TEntity, TKey, TReadModel>(this IServiceCollection services)
where TRepository : IMongoRepository<TEntity, TKey>
where TEntity : class, IHaveIdentifier<TKey>, new()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;
using System.Collections.Generic;
using System.Security.Principal;

using MediatR.CommandQuery.Definitions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using System;
using System.Threading;
using System.Threading.Tasks;

using MediatR.CommandQuery.Queries;

using Microsoft.Extensions.Logging;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

using MediatR.CommandQuery.Queries;

using Microsoft.Extensions.Logging;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using System;
using System.Threading;
using System.Threading.Tasks;

using MediatR.CommandQuery.Definitions;

using Microsoft.Extensions.Caching.Distributed;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using System;
using System.Threading;
using System.Threading.Tasks;

using MediatR.CommandQuery.Commands;
using MediatR.CommandQuery.Notifications;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Net;
using System.Threading;
using System.Threading.Tasks;

using MediatR.CommandQuery.Commands;
using MediatR.CommandQuery.Definitions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using System;
using System.Threading;
using System.Threading.Tasks;

using MediatR.CommandQuery.Commands;
using MediatR.CommandQuery.Definitions;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Security.Principal;
using System.Threading.Tasks;

using MediatR.CommandQuery.Definitions;
using MediatR.CommandQuery.Queries;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using System;
using System.Threading;
using System.Threading.Tasks;

using MediatR.CommandQuery.Definitions;
using MediatR.CommandQuery.Queries;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

using MediatR.CommandQuery.Definitions;
using MediatR.CommandQuery.Queries;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using System;
using System.Threading;
using System.Threading.Tasks;

using MediatR.CommandQuery.Commands;
using MediatR.CommandQuery.Definitions;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using System;
using System.Threading;
using System.Threading.Tasks;

using FluentValidation;

using MediatR.CommandQuery.Commands;
Expand Down
1 change: 0 additions & 1 deletion src/MediatR.CommandQuery/Commands/EntityDeleteCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Security.Principal;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Security.Principal;

Expand Down
3 changes: 0 additions & 3 deletions src/MediatR.CommandQuery/Commands/EntityIdentifiersCommand.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Security.Principal;

namespace MediatR.CommandQuery.Commands;
Expand Down
1 change: 0 additions & 1 deletion src/MediatR.CommandQuery/Commands/EntityModelCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Security.Principal;

Expand Down
1 change: 0 additions & 1 deletion src/MediatR.CommandQuery/Commands/EntityUpdateCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Security.Principal;

Expand Down
1 change: 0 additions & 1 deletion src/MediatR.CommandQuery/Commands/EntityUpsertCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Security.Principal;

Expand Down
1 change: 0 additions & 1 deletion src/MediatR.CommandQuery/Commands/PrincipalCommandBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Security.Principal;

namespace MediatR.CommandQuery.Commands;
Expand Down
2 changes: 0 additions & 2 deletions src/MediatR.CommandQuery/Definitions/ICacheQueryResult.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;

namespace MediatR.CommandQuery.Definitions;

public interface ICacheQueryResult
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Threading.Tasks;

namespace MediatR.CommandQuery.Definitions;

public interface IDistributedCacheSerializer
Expand Down
2 changes: 0 additions & 2 deletions src/MediatR.CommandQuery/Definitions/IHaveTenant.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Diagnostics.CodeAnalysis;

namespace MediatR.CommandQuery.Definitions;

/// <summary>
Expand Down
2 changes: 0 additions & 2 deletions src/MediatR.CommandQuery/Definitions/ITenantResolver.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Security.Principal;
using System.Threading.Tasks;

namespace MediatR.CommandQuery.Definitions;

Expand Down
2 changes: 0 additions & 2 deletions src/MediatR.CommandQuery/Definitions/ITrackCreated.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;

namespace MediatR.CommandQuery.Definitions;

public interface ITrackCreated
Expand Down
2 changes: 0 additions & 2 deletions src/MediatR.CommandQuery/Definitions/ITrackHistory.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;

namespace MediatR.CommandQuery.Definitions;

public interface ITrackHistory
Expand Down
2 changes: 0 additions & 2 deletions src/MediatR.CommandQuery/Definitions/ITrackUpdated.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;

namespace MediatR.CommandQuery.Definitions;

public interface ITrackUpdated
Expand Down
1 change: 0 additions & 1 deletion src/MediatR.CommandQuery/DomainException.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Net;

namespace MediatR.CommandQuery;
Expand Down
3 changes: 0 additions & 3 deletions src/MediatR.CommandQuery/Extensions/QueryExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Text;

Expand Down
2 changes: 0 additions & 2 deletions src/MediatR.CommandQuery/Extensions/TypeExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;

namespace MediatR.CommandQuery.Extensions;

public static class TypeExtensions
Expand Down
3 changes: 0 additions & 3 deletions src/MediatR.CommandQuery/Handlers/RequestHandlerBase.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;

using Microsoft.Extensions.Logging;

Expand Down
Loading

0 comments on commit 96c486e

Please sign in to comment.