Skip to content

Commit

Permalink
Feature/8.1.2 (#3)
Browse files Browse the repository at this point in the history
* Added NoRegisterAutomaticallyAttribute to avoid register instance of class automatically in DI.

* Added NoRegisterAutomaticallyAttribute to avoid register instance of class automatically in DI.

* Added NoRegisterAutomaticallyAttribute to avoid register instance of class automatically in DI.

* Added NoRegisterAutomaticallyAttribute to avoid register instance of class automatically in DI.

* Added NoRegisterAutomaticallyAttribute to avoid register instance of class automatically in DI.
  • Loading branch information
denis-peshkov committed Apr 3, 2024
1 parent 2ce7007 commit acc9fac
Show file tree
Hide file tree
Showing 15 changed files with 174 additions and 11 deletions.
6 changes: 6 additions & 0 deletions Cross.CQRS.sln
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_nuget", "_nuget", "{19139C
_nuget\pushSymbols.bat = _nuget\pushSymbols.bat
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleWebApp", "SampleWebApp\SampleWebApp.csproj", "{3433E255-17DF-4142-9507-7E34449947C0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -30,6 +32,10 @@ Global
{EAF0AC39-A26A-4432-8EA0-F1C9C01E3B06}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EAF0AC39-A26A-4432-8EA0-F1C9C01E3B06}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EAF0AC39-A26A-4432-8EA0-F1C9C01E3B06}.Release|Any CPU.Build.0 = Release|Any CPU
{3433E255-17DF-4142-9507-7E34449947C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3433E255-17DF-4142-9507-7E34449947C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3433E255-17DF-4142-9507-7E34449947C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3433E255-17DF-4142-9507-7E34449947C0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
9 changes: 9 additions & 0 deletions Cross.CQRS/Behaviors/NoRegisterAutomaticallyAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Cross.CQRS.Behaviors;

/// <summary>
/// Marker attribute to avoid register instance of class automatically in DI.
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
public sealed class NoRegisterAutomaticallyAttribute : Attribute
{
}
1 change: 0 additions & 1 deletion Cross.CQRS/Cross.CQRS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />

<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Scrutor" Version="4.2.2" />
</ItemGroup>

</Project>
16 changes: 15 additions & 1 deletion Cross.CQRS/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,26 @@

public static class ServiceCollectionExtensions
{
/// <summary>
/// Registers required services from the specified assemblies to the
/// specified <see cref="IServiceCollection"/>.
/// </summary>
/// <param name="services">The <see cref="IServiceCollection"/> to add the service to.</param>
/// <param name="assemblies">Assemblies to scan</param>
/// <returns>A reference to this instance after the operation has completed.</returns>
public static CqrsRegistrationSyntax AddCQRS(this IServiceCollection services, params Assembly[] assemblies)
{
var behaviorCollection = new BehaviorCollection(services);

// FluentValidation
services.AddValidatorsFromAssembly(assemblies.FirstOrDefault());
services.AddValidatorsFromAssembly(assemblies.FirstOrDefault(), ServiceLifetime.Scoped, result =>
{
var isNoRegisterAutomatically = result.ValidatorType
.GetCustomAttributes(typeof(NoRegisterAutomaticallyAttribute), inherit: false)
.Length != 0;
return !isNoRegisterAutomatically;
});

services.AddMediatR(o => o.AsScoped(), assemblies);

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Nuget](https://img.shields.io/nuget/v/Cross.CQRS.svg)](https://nuget.org/packages/Cross.CQRS/)
[![Nuget](https://img.shields.io/nuget/v/Cross.CQRS.svg)](https://nuget.org/packages/Cross.CQRS/) [![Documentation](https://img.shields.io/badge/docs-wiki-yellow.svg)](https://github.com/denis-peshkov/Cross.CQRS/wiki)

# Cross.CQRS

Expand Down
5 changes: 5 additions & 0 deletions ReleaseNotes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ Added support for .NET 8.
8.0.1 - 24 Nov 2023
Fixed unhandled exception on .NET 8. System.TypeLoadException: GenericArguments[0], 'TCommnd', on 'MediatR.IRequestHandler`2[TRequest,TResponse]' violates the constraint of type parameter 'TRequest'.
Upgrade packages.

8.1.2 - 3 Apr 2024
Added NoRegisterAutomaticallyAttribute to avoid register instance of class automatically in DI.
Small fixes.
Added sample project.
14 changes: 14 additions & 0 deletions SampleWebApp/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Global using directives

global using System;
global using System.Collections.Generic;
global using System.Linq;
global using System.Text;
global using System.Threading.Tasks;
global using Cross.CQRS;
global using Cross.CQRS.Behaviors;
global using Cross.CQRS.Queries;
global using FluentValidation;
global using Microsoft.AspNetCore.Builder;
global using Microsoft.Extensions.DependencyInjection;
global using Microsoft.Extensions.Hosting;
9 changes: 9 additions & 0 deletions SampleWebApp/Modules/Some/Handlers/SomeQuery.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace SampleWebApp.Modules.Some.Handlers;

public class SomeQuery : Query<IEnumerable<string>>
{

public SomeQuery()
{
}
}
9 changes: 9 additions & 0 deletions SampleWebApp/Modules/Some/Handlers/SomeQueryValidator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace SampleWebApp.Modules.Some.Handlers;

[NoRegisterAutomatically]
public class SomeQueryValidator : AbstractValidator<SomeQuery>
{
public SomeQueryValidator(string param1)
{
}
}
21 changes: 21 additions & 0 deletions SampleWebApp/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var builder = WebApplication.CreateBuilder(args);

// Add services to the container. Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddHttpContextAccessor();

//MediatR
builder.Services
.AddCQRS(typeof(Program).Assembly);

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.Run();
38 changes: 38 additions & 0 deletions SampleWebApp/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:40073",
"sslPort": 44303
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5001",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7115;http://localhost:5001",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
22 changes: 22 additions & 0 deletions SampleWebApp/SampleWebApp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>

<ItemGroup>
<Content Update="appsettings.Development.json">
<DependentUpon>appsettings.json</DependentUpon>
</Content>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Cross.CQRS\Cross.CQRS.csproj" />
</ItemGroup>

</Project>
8 changes: 8 additions & 0 deletions SampleWebApp/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions SampleWebApp/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
16 changes: 8 additions & 8 deletions _nuget/config.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,36 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>Cross.CQRS</id>
<version>8.0.1</version>
<version>8.1.2</version>
<authors>denis-peshkov</authors>
<owners>denis-peshkov</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<license type="expression">MIT</license>
<readme>docs\README.md</readme>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<projectUrl>https://github.com/denis-peshkov/Cross.CQRS</projectUrl>
<repository type="git" url="https://github.com/denis-peshkov/Cross.CQRS" />
<readme>docs\README.md</readme>
<icon>icon.png</icon>
<releaseNotes>
Fixed unhandled exception on .NET 8. System.TypeLoadException: GenericArguments[0], 'TCommnd', on 'MediatR.IRequestHandler`2[TRequest,TResponse]' violates the constraint of type parameter 'TRequest'.
Upgrade packages.
Added NoRegisterAutomaticallyAttribute to avoid register instance of class automatically in DI.
Small fixes.
Added sample project.
</releaseNotes>
<description>Simple .NET MediatR base Query, Command, Event. Event Queue and Validation behaviors. Written on C#.</description>
<tags>.NET Mediatr Query QueryHandler Command CommandHandler Event EventHandler EventQueueBehavior Validation ValidationBehavior SyntaxNotes NetCore</tags>
<repository type="git" url="https://github.com/denis-peshkov/Cross.CQRS" />
<dependencies>
<dependency id="FluentValidation" version="11.8.1" />
<dependency id="FluentValidation.DependencyInjectionExtensions" version="11.8.1" />
<dependency id="MediatR" version="11.1.0" />
<dependency id="MediatR.Extensions.Microsoft.DependencyInjection" version="11.1.0" />
<dependency id="Microsoft.Extensions.Configuration" version="8.0.0" />
<dependency id="Microsoft.CSharp" version="4.7.0" />
<dependency id="Scrutor" version="4.2.2" />
</dependencies>
</metadata>
<files>
<file src="..\Cross.CQRS\bin\Release\netstandard2.1\Cross.CQRS*.* " target="lib\netstandard2.1" />
<file src="..\Cross.CQRS\bin\Release\net6.0\Cross.CQRS*.* " target="lib\net6.0" />
<file src="..\Cross.CQRS\bin\Release\net7.0\Cross.CQRS*.* " target="lib\net7.0" />
<file src="..\Cross.CQRS\bin\Release\net7.0\Cross.CQRS*.* " target="lib\net8.0" />
<file src="..\Cross.CQRS\bin\Release\net8.0\Cross.CQRS*.* " target="lib\net8.0" />
<file src="..\README.md" target="docs\" />
<file src="..\icon.png" target="" />
</files>
Expand Down

0 comments on commit acc9fac

Please sign in to comment.