diff --git a/README.md b/README.md index 3e6a3f8..63d7d21 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![NuGet Version](https://img.shields.io/nuget/v/ServiceScan.SourceGenerator)](https://www.nuget.org/packages/ServiceScan.SourceGenerator/) Source generator for services registrations inspired by [Scrutor](https://github.com/khellang/Scrutor/). -Code generation allows to have AOT compatible code, without additional hit on startup performance due to runtime assembly scanning. +Code generation allows to have AOT-compatible code, without an additional hit on startup performance due to runtime assembly scanning. ## Installation Add the NuGet Package to your project: @@ -13,7 +13,7 @@ dotnet add package ServiceScan.SourceGenerator ## Usage `ServiceScan` generates a partial method implementation based on `GenerateServiceRegistrations` attribute. This attribute can be added to a partial method with `IServiceCollection` parameter. -For examples, based on the following partial method: +For example, based on the following partial method: ```csharp public static partial class ServicesExtensions { @@ -42,32 +42,32 @@ The only thing left is to invoke this method on your `IServiceCollection` instan ### Register all [FluentValidation](https://github.com/FluentValidation/FluentValidation) validators Unlike using `FluentValidation.DependencyInjectionExtensions` package, `ServiceScan` is AOT-compatible, and doesn't affect startup performance: ```csharp - [GenerateServiceRegistrations(AssignableTo = typeof(IValidator<>), Lifetime = ServiceLifetime.Singleton)] - public static partial IServiceCollection AddValidators(this IServiceCollection services); +[GenerateServiceRegistrations(AssignableTo = typeof(IValidator<>), Lifetime = ServiceLifetime.Singleton)] +public static partial IServiceCollection AddValidators(this IServiceCollection services); ``` ### Add [MediatR](https://github.com/jbogard/MediatR) handlers ```csharp - public static IServiceCollection AddMediatR(this IServiceCollection services) - { - return services - .AddTransient() - .AddMediatRHandlers(); - } +public static IServiceCollection AddMediatR(this IServiceCollection services) +{ + return services + .AddTransient() + .AddMediatRHandlers(); +} - [GenerateServiceRegistrations(AssignableTo = typeof(IRequestHandler<>), Lifetime = ServiceLifetime.Transient)] - [GenerateServiceRegistrations(AssignableTo = typeof(IRequestHandler<,>), Lifetime = ServiceLifetime.Transient)] - private static partial IServiceCollection AddMediatRHandlers(this IServiceCollection services); +[GenerateServiceRegistrations(AssignableTo = typeof(IRequestHandler<>), Lifetime = ServiceLifetime.Transient)] +[GenerateServiceRegistrations(AssignableTo = typeof(IRequestHandler<,>), Lifetime = ServiceLifetime.Transient)] +private static partial IServiceCollection AddMediatRHandlers(this IServiceCollection services); ``` It adds MediatR handlers, which would work for simple cases, although you might need to add other types like PipelineBehaviors or NotificationHandlers. ### Add all repository types from your project based on name filter as their implemented interfaces: ```csharp - [GenerateServiceRegistrations( - TypeNameFilter = "*Repository", - AsImplemetedInterfaces = true, - Lifetime = ServiceLifetime.Scoped)] - private static partial IServiceCollection AddRepositories(this IServiceCollection services); +[GenerateServiceRegistrations( + TypeNameFilter = "*Repository", + AsImplemetedInterfaces = true, + Lifetime = ServiceLifetime.Scoped)] +private static partial IServiceCollection AddRepositories(this IServiceCollection services); ``` ## Parameters