├── README-template.md ├── src ├── GraphR.Domain │ ├── Enums │ │ └── Category.cs │ ├── Entities │ │ ├── Author.cs │ │ └── Book.cs │ ├── Interfaces │ │ ├── Transaction │ │ │ └── ITransaction.cs │ │ └── Repositories │ │ │ ├── IAuthorRepository.cs │ │ │ └── IBookRepository.cs │ ├── GraphR.Domain.csproj │ └── Exceptions │ │ ├── BookNotFoundException.cs │ │ └── AuthorNotFoundException.cs ├── GraphR.API │ ├── appsettings.Development.json │ ├── GraphApi │ │ ├── Mutation.cs │ │ └── Query.cs │ ├── appsettings.json │ ├── ServiceCollectionExtensions.cs │ ├── Program.cs │ ├── GraphR.API.csproj │ └── Properties │ │ └── launchSettings.json ├── GraphR.Application │ ├── Authors │ │ ├── Types │ │ │ ├── Input │ │ │ │ └── AuthorParameters.cs │ │ │ ├── Output │ │ │ │ └── AuthorDto.cs │ │ │ └── Mappings │ │ │ │ └── AuthorMapping.cs │ │ ├── AuthorsQuery.cs │ │ └── Handlers │ │ │ ├── GetAuthorsQueryHandler.cs │ │ │ └── GetAuthorByIdHandler.cs │ ├── Books │ │ ├── Types │ │ │ ├── Input │ │ │ │ ├── GetBookByIdParameters.cs │ │ │ │ ├── GetBooksForAuthorParameters.cs │ │ │ │ └── CreateBookParameters.cs │ │ │ ├── Output │ │ │ │ └── BookDto.cs │ │ │ └── Mappings │ │ │ │ └── BookMapping.cs │ │ ├── BooksMutation.cs │ │ ├── BooksQuery.cs │ │ └── Handlers │ │ │ ├── Query │ │ │ ├── GetBookByIdQueryHandler.cs │ │ │ └── GetBooksForAuthorQueryHandler.cs │ │ │ └── Mutation │ │ │ └── CreateBookMutationHandler.cs │ ├── ServiceCollectionExtensions.cs │ └── GraphR.Application.csproj ├── GraphR.Core │ ├── Handlers │ │ ├── IHandler.cs │ │ ├── Handler.cs │ │ └── HandlersServiceCollectionExtensions.cs │ ├── GraphR.Core.csproj │ └── Dapper │ │ └── DapperMappingServiceCollectionExtensions.cs └── GraphR.Infrastructure │ ├── InfrastructureOptions.cs │ ├── Maps │ ├── AuthorMap.cs │ └── BookMap.cs │ ├── ServiceCollectionExtensions.cs │ ├── Database │ ├── DbConnectionProvider.cs │ ├── Seed │ │ ├── DbUpgraderBackgroundService.cs │ │ └── init_db.sql │ └── DbTransaction.cs │ ├── GraphR.Infrastructure.csproj │ └── Repositories │ ├── AuthorRepository.cs │ └── BookRepository.cs ├── .template.config └── template.json ├── GraphR.nuspec ├── LICENSE.txt ├── .gitattributes ├── .github └── workflows │ └── publish.yml ├── GraphR.sln ├── README.md ├── .gitignore └── .editorconfig /README-template.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/GraphR.Domain/Enums/Category.cs: -------------------------------------------------------------------------------- 1 | namespace GraphR.Domain.Enums; 2 | 3 | public enum Category 4 | { 5 | Bestseller, 6 | Educational, 7 | Cookbook, 8 | Manual 9 | } 10 | -------------------------------------------------------------------------------- /src/GraphR.API/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/GraphR.API/GraphApi/Mutation.cs: -------------------------------------------------------------------------------- 1 | using GraphR.Application.Books; 2 | 3 | namespace GraphR.API.GraphApi; 4 | 5 | public class Mutation 6 | { 7 | public BooksMutation Books() => new (); 8 | } 9 | -------------------------------------------------------------------------------- /src/GraphR.Application/Authors/Types/Input/AuthorParameters.cs: -------------------------------------------------------------------------------- 1 | namespace GraphR.Application.Authors.Types.Input; 2 | 3 | public sealed class AuthorParameters 4 | { 5 | public int Id { get; set; } 6 | } 7 | -------------------------------------------------------------------------------- /src/GraphR.Application/Books/Types/Input/GetBookByIdParameters.cs: -------------------------------------------------------------------------------- 1 | namespace GraphR.Application.Books.Types.Input; 2 | 3 | public sealed class GetBookByIdParameters 4 | { 5 | public int Id { get; set; } 6 | } 7 | -------------------------------------------------------------------------------- /src/GraphR.Application/Books/Types/Input/GetBooksForAuthorParameters.cs: -------------------------------------------------------------------------------- 1 | namespace GraphR.Application.Books.Types.Input; 2 | 3 | public sealed class GetBooksForAuthorParameters 4 | { 5 | public int AuthorId { get; set; } 6 | } 7 | -------------------------------------------------------------------------------- /src/GraphR.Domain/Entities/Author.cs: -------------------------------------------------------------------------------- 1 | namespace GraphR.Domain.Entities; 2 | 3 | public sealed class Author 4 | { 5 | public int Id { get; set; } 6 | 7 | public string Name { get; set; } 8 | 9 | public string Biography { get; set; } 10 | } 11 | -------------------------------------------------------------------------------- /src/GraphR.Domain/Interfaces/Transaction/ITransaction.cs: -------------------------------------------------------------------------------- 1 | namespace GraphR.Domain.Interfaces.Transaction; 2 | 3 | public interface ITransaction : IDisposable 4 | { 5 | void Begin(); 6 | 7 | void Commit(); 8 | 9 | void Rollback(); 10 | } 11 | -------------------------------------------------------------------------------- /src/GraphR.Core/Handlers/IHandler.cs: -------------------------------------------------------------------------------- 1 | namespace GrapR.Core.Handlers; 2 | 3 | public interface IHandler 4 | { 5 | Task Handle(); 6 | } 7 | 8 | public interface IHandler 9 | { 10 | Task Handle(TInput input); 11 | } 12 | -------------------------------------------------------------------------------- /src/GraphR.API/GraphApi/Query.cs: -------------------------------------------------------------------------------- 1 | using GraphR.Application.Authors; 2 | using GraphR.Application.Books; 3 | 4 | namespace GraphR.API.GraphApi; 5 | 6 | public class Query 7 | { 8 | public AuthorsQuery Authors => new(); 9 | 10 | public BooksQuery Books => new(); 11 | } 12 | -------------------------------------------------------------------------------- /src/GraphR.Domain/GraphR.Domain.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/GraphR.Domain/Interfaces/Repositories/IAuthorRepository.cs: -------------------------------------------------------------------------------- 1 | using GraphR.Domain.Entities; 2 | 3 | namespace GraphR.Domain.Interfaces.Repositories; 4 | public interface IAuthorRepository 5 | { 6 | Task GetById(int id); 7 | 8 | Task GetAll(); 9 | } 10 | -------------------------------------------------------------------------------- /src/GraphR.Application/Authors/Types/Output/AuthorDto.cs: -------------------------------------------------------------------------------- 1 | namespace GraphR.Application.Authors.Types.Output; 2 | 3 | public sealed class AuthorDto 4 | { 5 | public int Id { get; set; } 6 | 7 | public string Name { get; set; } 8 | 9 | public string Biography { get; set; } 10 | } 11 | -------------------------------------------------------------------------------- /src/GraphR.Application/Books/Types/Input/CreateBookParameters.cs: -------------------------------------------------------------------------------- 1 | namespace GraphR.Application.Books.Types.Input; 2 | public sealed class CreateBookParameters 3 | { 4 | public string Title { get; set; } 5 | 6 | public string Description { get; set; } 7 | 8 | public int AuthorId { get; set; } 9 | } 10 | -------------------------------------------------------------------------------- /src/GraphR.Application/Books/Types/Output/BookDto.cs: -------------------------------------------------------------------------------- 1 | namespace GraphR.Application.Books.Types.Output; 2 | 3 | public sealed class BookDto 4 | { 5 | public int Id { get; set; } 6 | 7 | public string Title { get; set; } 8 | 9 | public string Description { get; set; } 10 | 11 | public string Category { get; set; } 12 | } 13 | -------------------------------------------------------------------------------- /src/GraphR.Infrastructure/InfrastructureOptions.cs: -------------------------------------------------------------------------------- 1 | using Bindicate.Attributes.Options; 2 | 3 | namespace GrapR.Infrastructure; 4 | 5 | [RegisterOptions("Connections")] 6 | public class InfrastructureOptions 7 | { 8 | public string ConnectionString { get; set; } = ""; 9 | 10 | public string Schema { get; set; } = ""; 11 | } 12 | -------------------------------------------------------------------------------- /src/GraphR.Domain/Entities/Book.cs: -------------------------------------------------------------------------------- 1 | using GraphR.Domain.Enums; 2 | 3 | namespace GraphR.Domain.Entities; 4 | 5 | public sealed class Book 6 | { 7 | public int Id { get; set; } 8 | 9 | public string Title { get; set; } 10 | 11 | public string Description { get; set; } 12 | 13 | public Category Category { get; set; } 14 | } 15 | -------------------------------------------------------------------------------- /src/GraphR.Domain/Exceptions/BookNotFoundException.cs: -------------------------------------------------------------------------------- 1 | namespace GrapR.Domain.Exceptions; 2 | 3 | public sealed class BookNotFoundException : Exception 4 | { 5 | public BookNotFoundException(int id) 6 | : base($"Book with id {id} not found.") 7 | { 8 | Id = id; 9 | } 10 | 11 | public int Id { get; } 12 | } 13 | -------------------------------------------------------------------------------- /src/GraphR.Domain/Exceptions/AuthorNotFoundException.cs: -------------------------------------------------------------------------------- 1 | namespace GraphR.Domain.Exceptions; 2 | 3 | public sealed class AuthorNotFoundException : Exception 4 | { 5 | public AuthorNotFoundException(int id) 6 | : base($"Author with id {id} not found.") 7 | { 8 | Id = id; 9 | } 10 | 11 | public int Id { get; } 12 | } 13 | -------------------------------------------------------------------------------- /src/GraphR.API/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Connections": { 3 | "ConnectionString": "Server=(localdb)\\mssqllocaldb;Database=GrapRDb;Integrated Security=true;", 4 | "Schema": "" 5 | }, 6 | "Logging": { 7 | "LogLevel": { 8 | "Default": "Information", 9 | "Microsoft.AspNetCore": "Warning" 10 | } 11 | }, 12 | "AllowedHosts": "*" 13 | } 14 | -------------------------------------------------------------------------------- /src/GraphR.Domain/Interfaces/Repositories/IBookRepository.cs: -------------------------------------------------------------------------------- 1 | using GraphR.Domain.Entities; 2 | using GraphR.Domain.Enums; 3 | 4 | namespace GraphR.Domain.Interfaces.Repositories; 5 | 6 | public interface IBookRepository 7 | { 8 | Task GetById(int id); 9 | 10 | Task GetByAuthorId(int authorId); 11 | 12 | Task Create(string title, string description, Category category, int authorId); 13 | } 14 | -------------------------------------------------------------------------------- /src/GraphR.Infrastructure/Maps/AuthorMap.cs: -------------------------------------------------------------------------------- 1 | using Dapper.FluentMap.Mapping; 2 | using GraphR.Domain.Entities; 3 | 4 | namespace GraphR.Infrastructure.Maps; 5 | 6 | internal class AuthorMap : EntityMap 7 | { 8 | public AuthorMap() 9 | { 10 | Map(x => x.Id).ToColumn("Id"); 11 | Map(x => x.Name).ToColumn("Name"); 12 | Map(x => x.Biography).ToColumn("Biography"); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/GraphR.Application/ServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using GrapR.Core.Handlers; 2 | using Microsoft.Extensions.DependencyInjection; 3 | 4 | namespace GrapR.Application; 5 | 6 | public static class ServiceCollectionExtensions 7 | { 8 | public static IServiceCollection AddApplication(this IServiceCollection services) 9 | { 10 | services.AddHandlersInAssembly(); 11 | 12 | return services; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/GraphR.Application/Books/BooksMutation.cs: -------------------------------------------------------------------------------- 1 | using GraphR.Application.Books.Handlers.Mutation; 2 | using GraphR.Application.Books.Types.Input; 3 | using HotChocolate; 4 | 5 | namespace GraphR.Application.Books; 6 | 7 | public sealed class BooksMutation 8 | { 9 | public async Task CreateBook([Service] ICreateBookMutationHandler handler, CreateBookParameters parameters) 10 | => await handler.Handle(parameters); 11 | } 12 | -------------------------------------------------------------------------------- /src/GraphR.Infrastructure/Maps/BookMap.cs: -------------------------------------------------------------------------------- 1 | using GraphR.Domain.Entities; 2 | using Dapper.FluentMap.Mapping; 3 | 4 | namespace GraphR.Infrastructure.Maps; 5 | 6 | internal class BookMap : EntityMap 7 | { 8 | public BookMap() 9 | { 10 | Map(x => x.Id).ToColumn("Id"); 11 | Map(x => x.Title).ToColumn("Title"); 12 | Map(x => x.Description).ToColumn("Description"); 13 | Map(x => x.Category).ToColumn("Category"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/GraphR.API/ServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using GrapR.Application; 2 | using GrapR.Infrastructure; 3 | 4 | namespace GrapR.WebAPI; 5 | 6 | public static class ServiceCollectionExtensions 7 | { 8 | public static IServiceCollection AddSolutionComponents(this IServiceCollection services, IConfiguration configuration) 9 | { 10 | services.AddApplication(); 11 | services.AddInfrastructure(configuration); 12 | 13 | return services; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/GraphR.Core/GraphR.Core.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/GraphR.Application/Authors/AuthorsQuery.cs: -------------------------------------------------------------------------------- 1 | using GraphR.Application.Authors.Handlers; 2 | using GraphR.Application.Authors.Types.Input; 3 | using GraphR.Application.Authors.Types.Output; 4 | using HotChocolate; 5 | 6 | namespace GraphR.Application.Authors; 7 | 8 | public sealed class AuthorsQuery 9 | { 10 | public async Task Author([Service] IGetAuthorByIdHandler handler, AuthorParameters parameters) 11 | => await handler.Handle(parameters); 12 | 13 | public async Task Authors([Service] IGetAuthorsQueryHandler handler) => await handler.Handle(); 14 | } 15 | -------------------------------------------------------------------------------- /src/GraphR.Application/Authors/Types/Mappings/AuthorMapping.cs: -------------------------------------------------------------------------------- 1 | using GraphR.Application.Authors.Types.Output; 2 | using GraphR.Domain.Entities; 3 | 4 | namespace GraphR.Application.Authors.Types.Mappings; 5 | 6 | internal static class AuthorMapping 7 | { 8 | internal static AuthorDto[] ToOutput(this Author[] authors) 9 | => authors.Select(ToOutput).ToArray(); 10 | 11 | internal static AuthorDto ToOutput(this Author author) 12 | => new AuthorDto 13 | { 14 | Id = author.Id, 15 | Name = author.Name, 16 | Biography = author.Biography, 17 | }; 18 | } 19 | -------------------------------------------------------------------------------- /src/GraphR.API/Program.cs: -------------------------------------------------------------------------------- 1 | using GraphR.API.GraphApi; 2 | using GrapR.WebAPI; 3 | 4 | var builder = WebApplication.CreateBuilder(args); 5 | var configuration = builder.Configuration; 6 | 7 | // Add services to the container. 8 | builder.Services.AddSolutionComponents(configuration); 9 | 10 | builder.Services.AddGraphQLServer() 11 | .AddQueryType() 12 | .AddMutationType(); 13 | 14 | builder.Services.AddControllers(); 15 | 16 | var app = builder.Build(); 17 | 18 | app.MapGraphQL(); 19 | 20 | app.UseHttpsRedirection(); 21 | 22 | app.UseAuthorization(); 23 | 24 | app.MapControllers(); 25 | 26 | app.Run(); 27 | -------------------------------------------------------------------------------- /src/GraphR.Application/Books/Types/Mappings/BookMapping.cs: -------------------------------------------------------------------------------- 1 | using GraphR.Application.Books.Types.Output; 2 | using GraphR.Domain.Entities; 3 | 4 | namespace GraphR.Application.Books.Types.Mappings; 5 | 6 | internal static class BookMapping 7 | { 8 | internal static BookDto ToOutput(this Book book) 9 | => new BookDto 10 | { 11 | Id = book.Id, 12 | Title = book.Title, 13 | Description = book.Description, 14 | Category = book.Category.ToString(), 15 | }; 16 | 17 | internal static BookDto[] ToOutput(this Book[] books) 18 | => books.Select(ToOutput).ToArray(); 19 | } 20 | -------------------------------------------------------------------------------- /src/GraphR.Application/Books/BooksQuery.cs: -------------------------------------------------------------------------------- 1 | using GraphR.Application.Books.Handlers.Query; 2 | using GraphR.Application.Books.Types.Input; 3 | using GraphR.Application.Books.Types.Output; 4 | using HotChocolate; 5 | 6 | namespace GraphR.Application.Books; 7 | 8 | public sealed class BooksQuery 9 | { 10 | public async Task Book([Service] IGetBookByIdHandler handler, GetBookByIdParameters parameters) 11 | => await handler.Handle(parameters); 12 | 13 | public async Task BooksForAuthor([Service] IGetBooksForAuthorQueryHandler handler, GetBooksForAuthorParameters parameters) 14 | => await handler.Handle(parameters); 15 | } 16 | -------------------------------------------------------------------------------- /src/GraphR.API/GraphR.API.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | false 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/GraphR.Application/GraphR.Application.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/GraphR.Core/Handlers/Handler.cs: -------------------------------------------------------------------------------- 1 | using FluentValidation; 2 | 3 | namespace GrapR.Core.Handlers; 4 | 5 | public abstract class Handler 6 | : IHandler 7 | { 8 | public abstract Task Handle(); 9 | } 10 | 11 | public abstract class Handler 12 | : AbstractValidator, IHandler 13 | { 14 | public async Task Handle(TInput input) 15 | { 16 | DefineRules(); 17 | this.ValidateAndThrow(input); 18 | return await HandleValidatedRequest(input); 19 | } 20 | 21 | protected abstract void DefineRules(); 22 | 23 | protected abstract Task HandleValidatedRequest(TInput input); 24 | } 25 | -------------------------------------------------------------------------------- /src/GraphR.Application/Authors/Handlers/GetAuthorsQueryHandler.cs: -------------------------------------------------------------------------------- 1 | using GraphR.Application.Authors.Types.Mappings; 2 | using GraphR.Application.Authors.Types.Output; 3 | using GraphR.Domain.Interfaces.Repositories; 4 | using GrapR.Core.Handlers; 5 | 6 | namespace GraphR.Application.Authors.Handlers; 7 | 8 | internal sealed class GetAuthorsQueryHandler : Handler, IGetAuthorsQueryHandler 9 | { 10 | private readonly IAuthorRepository _repository; 11 | 12 | public GetAuthorsQueryHandler(IAuthorRepository repository) 13 | { 14 | _repository = repository; 15 | } 16 | 17 | public override async Task Handle() 18 | => (await _repository.GetAll()).ToOutput(); 19 | } 20 | 21 | public interface IGetAuthorsQueryHandler : IHandler { } 22 | -------------------------------------------------------------------------------- /src/GraphR.Infrastructure/ServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using Bindicate; 3 | using GrapR.Core.Dapper; 4 | using GrapR.Infrastructure.Database.Seed; 5 | using Microsoft.Extensions.Configuration; 6 | using Microsoft.Extensions.DependencyInjection; 7 | 8 | namespace GrapR.Infrastructure; 9 | 10 | public static class ServiceCollectionExtensions 11 | { 12 | public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration) 13 | { 14 | services.AddAutowiringForAssembly(Assembly.GetExecutingAssembly()) 15 | .WithOptions(configuration) 16 | .Register(); 17 | 18 | services.AddDapperFluentMappingsInAssembly(); 19 | 20 | services.AddHostedService(); 21 | 22 | return services; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /.template.config/template.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/template", 3 | "author": "Tim Maes", 4 | "classifications": [ "Web", "API", "GraphQL", "Dapper" ], 5 | "identity": "GraphR.Template", 6 | "name": "GraphR Graph API Template", 7 | "shortName": "graphr", 8 | "tags": { 9 | "language": "C#", 10 | "type": "project" 11 | }, 12 | "sourceName": "GraphR", 13 | "symbols": { 14 | "NAMESPACE": { 15 | "type": "parameter", 16 | "replaces": "GraphR", 17 | "defaultValue": "GraphR" 18 | } 19 | }, 20 | "sources": [ 21 | { 22 | "source": "./", 23 | "target": "./", 24 | "exclude": [ 25 | ".template.config/**/*", 26 | "*.nuspec", 27 | "README.md", 28 | "LICENSE.txt", 29 | "template.json" 30 | ], 31 | "rename": { 32 | "README-template.md": "README.md" 33 | } 34 | } 35 | ] 36 | } 37 | -------------------------------------------------------------------------------- /src/GraphR.Infrastructure/Database/DbConnectionProvider.cs: -------------------------------------------------------------------------------- 1 | using System.Data; 2 | using Bindicate.Attributes; 3 | using Microsoft.Data.SqlClient; 4 | using Microsoft.Extensions.Options; 5 | 6 | namespace GrapR.Infrastructure.Database; 7 | 8 | [AddTransient(typeof(IDbConnectionProvider))] 9 | public class DbConnectionProvider : IDbConnectionProvider 10 | { 11 | private readonly IOptions _options; 12 | 13 | public DbConnectionProvider(IOptions options) 14 | { 15 | _options = options; 16 | } 17 | 18 | public IDbConnection CreateConnection() 19 | { 20 | var connection = new SqlConnection(_options.Value.ConnectionString); 21 | connection.Open(); 22 | return connection; 23 | } 24 | 25 | public string Schema { get; } 26 | } 27 | 28 | public interface IDbConnectionProvider 29 | { 30 | IDbConnection CreateConnection(); 31 | string Schema { get; } 32 | } 33 | -------------------------------------------------------------------------------- /src/GraphR.Infrastructure/Database/Seed/DbUpgraderBackgroundService.cs: -------------------------------------------------------------------------------- 1 | using DbUp; 2 | using Microsoft.Extensions.Hosting; 3 | using Microsoft.Extensions.Options; 4 | 5 | namespace GrapR.Infrastructure.Database.Seed; 6 | 7 | public class DbUpgraderBackgroundService : BackgroundService 8 | { 9 | readonly string _connectionString; 10 | 11 | public DbUpgraderBackgroundService(IOptions options) => 12 | _connectionString = options.Value.ConnectionString; 13 | 14 | protected override Task ExecuteAsync(CancellationToken stoppingToken) 15 | { 16 | #if DEBUG 17 | EnsureDatabase.For.SqlDatabase(_connectionString); 18 | 19 | var result = DeployChanges.To 20 | .SqlDatabase(_connectionString) 21 | .WithScriptsEmbeddedInAssembly(GetType().Assembly) 22 | .LogToConsole() 23 | .Build().PerformUpgrade(); 24 | 25 | if (!result.Successful) 26 | throw result.Error; 27 | #endif 28 | 29 | return Task.CompletedTask; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /GraphR.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | GraphR 5 | 0.2.2 6 | Tim Maes 7 | false 8 | MIT 9 | https://github.com/Tim-Maes/GraphR 10 | 11 | Solution template for GraphAPI with Dapper 12 | $copyright$ 13 | dotnet-core graph api csharp dapper template 14 | 15 | 16 | 17 | README.md 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/GraphR.Application/Books/Handlers/Query/GetBookByIdQueryHandler.cs: -------------------------------------------------------------------------------- 1 | using GrapR.Core.Handlers; 2 | using FluentValidation; 3 | using GraphR.Application.Books.Types.Input; 4 | using GraphR.Application.Books.Types.Output; 5 | using GraphR.Application.Books.Types.Mappings; 6 | using GraphR.Domain.Interfaces.Repositories; 7 | 8 | namespace GraphR.Application.Books.Handlers.Query; 9 | 10 | internal sealed class GetBookByIdQueryHandler : Handler, IGetBookByIdHandler 11 | { 12 | private readonly IBookRepository _bookRepository; 13 | 14 | public GetBookByIdQueryHandler(IBookRepository bookRepository) 15 | { 16 | _bookRepository = bookRepository; 17 | } 18 | 19 | protected override void DefineRules() 20 | { 21 | RuleFor(x => x.Id).GreaterThan(0); 22 | } 23 | 24 | protected override async Task HandleValidatedRequest(GetBookByIdParameters request) 25 | => (await _bookRepository.GetById(request.Id)).ToOutput(); 26 | } 27 | 28 | public interface IGetBookByIdHandler : IHandler { } 29 | -------------------------------------------------------------------------------- /src/GraphR.Application/Authors/Handlers/GetAuthorByIdHandler.cs: -------------------------------------------------------------------------------- 1 | using FluentValidation; 2 | using GraphR.Application.Authors.Types.Input; 3 | using GraphR.Application.Authors.Types.Mappings; 4 | using GraphR.Application.Authors.Types.Output; 5 | using GraphR.Domain.Interfaces.Repositories; 6 | using GrapR.Core.Handlers; 7 | 8 | namespace GraphR.Application.Authors.Handlers; 9 | 10 | internal sealed class GetAuthorByIdHandler : Handler, IGetAuthorByIdHandler 11 | { 12 | private readonly IAuthorRepository _authorRepository; 13 | 14 | public GetAuthorByIdHandler(IAuthorRepository authorRepository) 15 | { 16 | _authorRepository = authorRepository; 17 | } 18 | 19 | protected override void DefineRules() 20 | { 21 | RuleFor(x => x.Id).GreaterThan(0); 22 | } 23 | 24 | protected override async Task HandleValidatedRequest(AuthorParameters input) 25 | => (await _authorRepository.GetById(id: input.Id)).ToOutput(); 26 | } 27 | 28 | public interface IGetAuthorByIdHandler: IHandler 29 | { 30 | } 31 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Tim Maes 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/GraphR.Application/Books/Handlers/Query/GetBooksForAuthorQueryHandler.cs: -------------------------------------------------------------------------------- 1 | using FluentValidation; 2 | using GraphR.Application.Books.Types.Input; 3 | using GraphR.Application.Books.Types.Mappings; 4 | using GraphR.Application.Books.Types.Output; 5 | using GraphR.Domain.Interfaces.Repositories; 6 | using GrapR.Core.Handlers; 7 | 8 | namespace GraphR.Application.Books.Handlers.Query; 9 | internal sealed class GetBooksForAuthorQueryHandler 10 | : Handler, IGetBooksForAuthorQueryHandler 11 | { 12 | private readonly IBookRepository _bookRepository; 13 | 14 | public GetBooksForAuthorQueryHandler(IBookRepository bookRepository) 15 | { 16 | _bookRepository = bookRepository; 17 | } 18 | 19 | protected override void DefineRules() 20 | { 21 | RuleFor(x => x.AuthorId).GreaterThan(0); 22 | } 23 | 24 | protected override async Task HandleValidatedRequest(GetBooksForAuthorParameters request) 25 | => (await _bookRepository.GetByAuthorId(request.AuthorId)).ToOutput(); 26 | } 27 | 28 | public interface IGetBooksForAuthorQueryHandler : IHandler { } 29 | -------------------------------------------------------------------------------- /src/GraphR.API/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:5559", 8 | "sslPort": 44352 9 | } 10 | }, 11 | "profiles": { 12 | "http": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "applicationUrl": "http://localhost:5230", 17 | "environmentVariables": { 18 | "ASPNETCORE_ENVIRONMENT": "Development" 19 | } 20 | }, 21 | "https": { 22 | "commandName": "Project", 23 | "dotnetRunMessages": true, 24 | "launchBrowser": true, 25 | "applicationUrl": "https://localhost:7157;http://localhost:5230", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | }, 30 | "IIS Express": { 31 | "commandName": "IISExpress", 32 | "launchBrowser": true, 33 | "environmentVariables": { 34 | "ASPNETCORE_ENVIRONMENT": "Development" 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/GraphR.Application/Books/Handlers/Mutation/CreateBookMutationHandler.cs: -------------------------------------------------------------------------------- 1 | using FluentValidation; 2 | using GraphR.Application.Books.Types.Input; 3 | using GraphR.Domain.Enums; 4 | using GraphR.Domain.Interfaces.Repositories; 5 | using GrapR.Core.Handlers; 6 | 7 | namespace GraphR.Application.Books.Handlers.Mutation; 8 | 9 | internal class CreateBookMutationHandler : Handler, 10 | ICreateBookMutationHandler 11 | { 12 | private readonly IBookRepository _repository; 13 | 14 | public CreateBookMutationHandler(IBookRepository repository) 15 | { 16 | _repository = repository; 17 | } 18 | 19 | protected override void DefineRules() 20 | { 21 | RuleFor(x => x.Title).NotEmpty(); 22 | RuleFor(x => x.Description).NotEmpty(); 23 | RuleFor(x => x.AuthorId).GreaterThan(0); 24 | } 25 | 26 | protected override async Task HandleValidatedRequest(CreateBookParameters input) 27 | { 28 | await _repository.Create( 29 | title: input.Title, 30 | description: input.Description, 31 | category: Category.Educational, 32 | authorId: input.AuthorId); 33 | 34 | return 1; 35 | } 36 | } 37 | 38 | public interface ICreateBookMutationHandler : IHandler { } 39 | -------------------------------------------------------------------------------- /src/GraphR.Core/Handlers/HandlersServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using Microsoft.Extensions.DependencyInjection; 3 | 4 | namespace GrapR.Core.Handlers; 5 | 6 | public static class HandlersServiceCollectionExtensions 7 | { 8 | public static IServiceCollection AddHandlersInAssembly(this IServiceCollection services) 9 | { 10 | var assembly = Assembly.GetCallingAssembly(); 11 | foreach (Type implementationType in assembly.GetTypes().Where(IsNonAbstractClass)) 12 | { 13 | foreach (Type interfaceType in FindInterfaceTypesInAssembly(implementationType)) 14 | services.AddScoped(interfaceType, implementationType); 15 | } 16 | 17 | return services; 18 | } 19 | 20 | private static bool IsNonAbstractClass(Type type) 21 | => type.IsClass && !type.IsAbstract; 22 | 23 | private static IEnumerable FindInterfaceTypesInAssembly(Type type) 24 | { 25 | Type[] interfaceTypes = type.GetInterfaces(); 26 | if (interfaceTypes.Any(IsGenericHandlerInterface)) 27 | return interfaceTypes.Where(x => x.Assembly == type.Assembly); 28 | return Enumerable.Empty(); 29 | } 30 | 31 | private static bool IsGenericHandlerInterface(Type x) 32 | => x.IsGenericType && (x.GetGenericTypeDefinition() == typeof(IHandler<,>) || x.GetGenericTypeDefinition() == typeof(IHandler<>)); 33 | } 34 | -------------------------------------------------------------------------------- /src/GraphR.Core/Dapper/DapperMappingServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using Dapper.FluentMap; 3 | using Dapper.FluentMap.Configuration; 4 | using Dapper.FluentMap.Mapping; 5 | using Microsoft.Extensions.DependencyInjection; 6 | 7 | namespace GrapR.Core.Dapper; 8 | 9 | public static class DapperMappingServiceCollectionExtensions 10 | { 11 | public static IServiceCollection AddDapperFluentMappingsInAssembly(this IServiceCollection services) 12 | { 13 | var assembly = Assembly.GetCallingAssembly(); 14 | 15 | FluentMapper.Initialize(configuration => 16 | { 17 | IEnumerable<(Type MapType, Type InterfaceType)> mappings = assembly.GetTypes() 18 | .Select(x => (mapType: x, entityType: x.GetInterface(typeof(IEntityMap<>).Name)?.GetGenericArguments()[0])) 19 | .Where(x => x.entityType != null); 20 | 21 | foreach ((Type mapType, Type entityType) in mappings) 22 | { 23 | MethodInfo addMapMethod = typeof(FluentMapConfiguration).GetMethod(nameof(FluentMapConfiguration.AddMap), BindingFlags.Public | BindingFlags.Instance) 24 | .MakeGenericMethod(entityType); 25 | var map = Activator.CreateInstance(mapType); 26 | addMapMethod.Invoke(configuration, new object[] { map }); 27 | } 28 | }); 29 | 30 | return services; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/GraphR.Infrastructure/GraphR.Infrastructure.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | false 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /src/GraphR.Infrastructure/Database/Seed/init_db.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE Category ( 2 | CategoryID INT PRIMARY KEY, 3 | Name NVARCHAR(50) NOT NULL 4 | ); 5 | 6 | INSERT INTO Category (CategoryID, Name) VALUES 7 | (1, 'Bestseller'), 8 | (2, 'Educational'), 9 | (3, 'Cookbook'), 10 | (4, 'Manual'); 11 | GO 12 | 13 | CREATE TABLE Author ( 14 | Id INT PRIMARY KEY IDENTITY, 15 | Name NVARCHAR(100) NOT NULL, 16 | Biography NVARCHAR(255) 17 | ); 18 | GO 19 | 20 | INSERT INTO Author (Name, Biography) VALUES 21 | ('Author One', 'Biography of Author One'), 22 | ('Author Two', 'Biography of Author Two'), 23 | ('Author Three', 'Biography of Author Three'); 24 | GO 25 | 26 | CREATE TABLE Book ( 27 | Id INT PRIMARY KEY IDENTITY, 28 | Title NVARCHAR(100) NOT NULL, 29 | Description NVARCHAR(255), 30 | CategoryID INT NOT NULL, 31 | AuthorID INT NOT NULL, 32 | CONSTRAINT FK_Book_Category FOREIGN KEY (CategoryID) REFERENCES Category(CategoryID), 33 | CONSTRAINT FK_Book_Author FOREIGN KEY (AuthorID) REFERENCES Author(Id) 34 | ); 35 | GO 36 | 37 | INSERT INTO Book (Title, Description, CategoryID, AuthorID) VALUES 38 | ('Book Title One', 'Description of Book One', 1, 1), 39 | ('Book Title Two', 'Description of Book Two', 2, 2), 40 | ('Book Title Three', 'Description of Book Three', 3, 3), 41 | ('Book Title Four', 'Description of Book Four', 1, 1), 42 | ('Book Title Five', 'Description of Book Five', 2, 1), 43 | ('Book Title Six', 'Description of Book Six', 3, 2), 44 | ('Book Title Seven', 'Description of Book Seven', 1, 2), 45 | ('Book Title Eight', 'Description of Book Eight', 2, 3); 46 | 47 | GO 48 | -------------------------------------------------------------------------------- /src/GraphR.Infrastructure/Repositories/AuthorRepository.cs: -------------------------------------------------------------------------------- 1 | using Bindicate.Attributes; 2 | using Dapper; 3 | using GraphR.Domain.Entities; 4 | using GraphR.Domain.Exceptions; 5 | using GraphR.Domain.Interfaces.Repositories; 6 | using GrapR.Infrastructure.Database; 7 | 8 | namespace GrapR.Infrastructure.Repositories; 9 | 10 | [AddTransient(typeof(IAuthorRepository))] 11 | public class AuthorRepository : IAuthorRepository 12 | { 13 | private readonly IDbConnectionProvider _dbConnectionProvider; 14 | 15 | public AuthorRepository(IDbConnectionProvider dbConnectionProvider) 16 | { 17 | _dbConnectionProvider = dbConnectionProvider; 18 | } 19 | 20 | public async Task GetAll() 21 | { 22 | 23 | var query = 24 | """ 25 | SELECT Name, Biography 26 | FROM dbo.Author 27 | """; 28 | 29 | using (var connection = _dbConnectionProvider.CreateConnection()) 30 | { 31 | return (await connection.QueryAsync( 32 | sql: query)).ToArray(); 33 | } 34 | } 35 | 36 | public async Task GetById(int id) 37 | { 38 | var query = 39 | """ 40 | SELECT Name, Biography 41 | FROM dbo.Author 42 | WHERE Id = @Id 43 | """; 44 | 45 | var parameters = new DynamicParameters(); 46 | parameters.Add("Id", id); 47 | 48 | using (var connection = _dbConnectionProvider.CreateConnection()) 49 | { 50 | return await connection.QueryFirstOrDefaultAsync( 51 | sql: query, 52 | param: parameters) 53 | ?? throw new AuthorNotFoundException(id); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/GraphR.Infrastructure/Database/DbTransaction.cs: -------------------------------------------------------------------------------- 1 | using System.Data; 2 | using Bindicate.Attributes; 3 | using GraphR.Domain.Interfaces.Transaction; 4 | using GrapR.Infrastructure.Database; 5 | 6 | namespace GraphR.Infrastructure.Database; 7 | 8 | [AddTransient(typeof(ITransaction))] 9 | public class DbTransaction : ITransaction 10 | { 11 | private readonly IDbConnectionProvider _connectionProvider; 12 | private IDbConnection _connection; 13 | private IDbTransaction _transaction; 14 | private bool _disposed; 15 | 16 | public DbTransaction(IDbConnectionProvider connectionProvider) 17 | { 18 | _connectionProvider = connectionProvider; 19 | } 20 | 21 | public void Begin() 22 | { 23 | if (_connection is null) _connection = _connectionProvider.CreateConnection(); 24 | 25 | if (_connection.State is not ConnectionState.Open) _connection.Open(); 26 | 27 | _transaction = _connection.BeginTransaction(); 28 | } 29 | 30 | public void Commit() 31 | { 32 | try 33 | { 34 | _transaction?.Commit(); 35 | } 36 | catch 37 | { 38 | Rollback(); 39 | throw; 40 | } 41 | finally 42 | { 43 | DisposeTransaction(); 44 | } 45 | } 46 | 47 | public void Rollback() 48 | { 49 | _transaction?.Rollback(); 50 | DisposeTransaction(); 51 | } 52 | 53 | private void DisposeTransaction() 54 | { 55 | _transaction?.Dispose(); 56 | _transaction = null; 57 | } 58 | 59 | public void Dispose() 60 | { 61 | if (_disposed) 62 | return; 63 | 64 | _disposed = true; 65 | DisposeTransaction(); 66 | 67 | if (_connection is null) 68 | { 69 | _connection.Dispose(); 70 | _connection = null; 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | # yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json 2 | 3 | name: publish 4 | on: 5 | workflow_dispatch: # Allow running the workflow manually from the GitHub UI 6 | push: 7 | branches: 8 | - 'master' # Run the workflow when pushing to the main branch 9 | pull_request: 10 | branches: 11 | - '*' # Run the workflow for all pull requests 12 | release: 13 | types: 14 | - published # Run the workflow when a new GitHub release is published 15 | 16 | env: 17 | DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 18 | DOTNET_NOLOGO: true 19 | NuGetDirectory: ${{ github.workspace}}/nuget 20 | 21 | defaults: 22 | run: 23 | shell: pwsh 24 | 25 | jobs: 26 | create_nuget: 27 | runs-on: ubuntu-latest 28 | steps: 29 | - uses: actions/checkout@v3 30 | with: 31 | fetch-depth: 0 # Get all history to allow automatic versioning using MinVer 32 | 33 | # Install the .NET SDK indicated in the global.json file 34 | - name: Setup .NET 35 | uses: nuget/setup-nuget@v1 36 | 37 | # Create the NuGet package in the folder from the environment variable NuGetDirectory 38 | - run: nuget pack GraphR.nuspec -NoDefaultExcludes -OutputDirectory ${{ env.NuGetDirectory }} 39 | 40 | # Publish the NuGet package as an artifact, so they can be used in the following jobs 41 | - uses: actions/upload-artifact@v3 42 | with: 43 | name: nuget 44 | if-no-files-found: error 45 | retention-days: 7 46 | path: ${{ env.NuGetDirectory }}/*.nupkg 47 | 48 | deploy: 49 | # Publish only when creating a GitHub Release 50 | # https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository 51 | # You can update this logic if you want to manage releases differently 52 | if: github.event_name == 'release' 53 | runs-on: ubuntu-latest 54 | needs: [ create_nuget ] 55 | steps: 56 | # Download the NuGet package created in the previous job 57 | - uses: actions/download-artifact@v3 58 | with: 59 | name: nuget 60 | path: ${{ env.NuGetDirectory }} 61 | 62 | # Install the .NET SDK indicated in the global.json file 63 | - name: Setup .NET Core 64 | uses: actions/setup-dotnet@v3 65 | 66 | # Publish all NuGet packages to NuGet.org 67 | # Use --skip-duplicate to prevent errors if a package with the same version already exists. 68 | # If you retry a failed workflow, already published packages will be skipped without error. 69 | - name: Publish NuGet package 70 | run: | 71 | foreach($file in (Get-ChildItem "${{ env.NuGetDirectory }}" -Recurse -Include *.nupkg)) { 72 | dotnet nuget push $file --api-key "${{ secrets.NUGET_API_KEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate 73 | } 74 | -------------------------------------------------------------------------------- /src/GraphR.Infrastructure/Repositories/BookRepository.cs: -------------------------------------------------------------------------------- 1 | using Bindicate.Attributes; 2 | using GrapR.Domain.Exceptions; 3 | using GraphR.Domain.Entities; 4 | using GrapR.Infrastructure.Database; 5 | using Dapper; 6 | using GraphR.Domain.Enums; 7 | using GraphR.Domain.Interfaces.Repositories; 8 | 9 | namespace GrapR.Infrastructure.Repositories; 10 | 11 | [AddTransient(typeof(IBookRepository))] 12 | public class BookRepository : IBookRepository 13 | { 14 | private readonly IDbConnectionProvider _dbConnectionProvider; 15 | 16 | public BookRepository(IDbConnectionProvider dbConnectionProvider) 17 | { 18 | _dbConnectionProvider = dbConnectionProvider; 19 | } 20 | 21 | public async Task GetById(int id) 22 | { 23 | var query = 24 | """ 25 | SELECT Id, Title, Description, CategoryId, AuthorId 26 | FROM dbo.Book 27 | WHERE Id = @Id 28 | """; 29 | 30 | var parameters = new DynamicParameters(); 31 | parameters.Add("Id", id); 32 | 33 | using (var connection = _dbConnectionProvider.CreateConnection()) 34 | { 35 | return await connection.QueryFirstOrDefaultAsync( 36 | sql: query, 37 | param: parameters) 38 | ?? throw new BookNotFoundException(id); 39 | } 40 | } 41 | 42 | public async Task GetByAuthorId(int authorId) 43 | { 44 | var query = 45 | """ 46 | SELECT Id, Title, Description, CategoryId, AuthorId 47 | FROM dbo.Book 48 | WHERE AuthorID = @AuthorId 49 | """; 50 | 51 | var parameters = new DynamicParameters(); 52 | parameters.Add("AuthorId", authorId); 53 | 54 | using (var connection = _dbConnectionProvider.CreateConnection()) 55 | { 56 | return (await connection.QueryAsync( 57 | sql: query, 58 | param: parameters)).ToArray(); 59 | } 60 | 61 | } 62 | 63 | public async Task Create(string title, string description, Category category, int authorId) 64 | { 65 | var query = 66 | """ 67 | INSERT INTO dbo.book 68 | (Title, Description, CategoryId, AuthorId) 69 | VALUES 70 | (@Title, @Description, @CategoryId, @AuthorId) 71 | """; 72 | 73 | var parameters = new DynamicParameters(); 74 | parameters.Add("Title", title); 75 | parameters.Add("Description", description); 76 | parameters.Add("CategoryId", (int)category); 77 | parameters.Add("AuthorId", authorId); 78 | 79 | using (var connection = _dbConnectionProvider.CreateConnection()) 80 | { 81 | await connection.ExecuteAsync( 82 | sql: query, 83 | param: parameters); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /GraphR.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.8.34309.116 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GraphR.API", "src\GraphR.API\GraphR.API.csproj", "{45D0FC5B-588C-4A1B-B69E-BC35E26EFD11}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GraphR.Application", "src\GraphR.Application\GraphR.Application.csproj", "{6E5FE161-0376-4F28-AA70-3745A44EE028}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GraphR.Domain", "src\GraphR.Domain\GraphR.Domain.csproj", "{93267F8C-80FF-41F0-9316-C3969B81C681}" 11 | EndProject 12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GraphR.Infrastructure", "src\GraphR.Infrastructure\GraphR.Infrastructure.csproj", "{93D27EB7-BB64-44AB-9B6E-C5071AFF0E48}" 13 | EndProject 14 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "01 API", "01 API", "{D234312E-31D1-47BF-B883-DC933726200D}" 15 | EndProject 16 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "02 Application", "02 Application", "{A7C973C5-8F83-4665-AD0B-10A1B6020FDE}" 17 | EndProject 18 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "03 Core", "03 Core", "{9D2309C2-3DF8-4338-9A79-C7D894470E5F}" 19 | EndProject 20 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "00 Solution Items", "00 Solution Items", "{51F4CC59-B5A0-44BA-A94A-3A01AA88B6AA}" 21 | ProjectSection(SolutionItems) = preProject 22 | .editorconfig = .editorconfig 23 | .gitignore = .gitignore 24 | GraphR.nuspec = GraphR.nuspec 25 | README.md = README.md 26 | README-template.md = README-template.md 27 | .template.config\template.json = .template.config\template.json 28 | EndProjectSection 29 | EndProject 30 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GraphR.Core", "src\GraphR.Core\GraphR.Core.csproj", "{B6B07DE4-48AD-4FA1-82AE-50FC10798C86}" 31 | EndProject 32 | Global 33 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 34 | Debug|Any CPU = Debug|Any CPU 35 | Release|Any CPU = Release|Any CPU 36 | EndGlobalSection 37 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 38 | {45D0FC5B-588C-4A1B-B69E-BC35E26EFD11}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 39 | {45D0FC5B-588C-4A1B-B69E-BC35E26EFD11}.Debug|Any CPU.Build.0 = Debug|Any CPU 40 | {45D0FC5B-588C-4A1B-B69E-BC35E26EFD11}.Release|Any CPU.ActiveCfg = Release|Any CPU 41 | {45D0FC5B-588C-4A1B-B69E-BC35E26EFD11}.Release|Any CPU.Build.0 = Release|Any CPU 42 | {6E5FE161-0376-4F28-AA70-3745A44EE028}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 43 | {6E5FE161-0376-4F28-AA70-3745A44EE028}.Debug|Any CPU.Build.0 = Debug|Any CPU 44 | {6E5FE161-0376-4F28-AA70-3745A44EE028}.Release|Any CPU.ActiveCfg = Release|Any CPU 45 | {6E5FE161-0376-4F28-AA70-3745A44EE028}.Release|Any CPU.Build.0 = Release|Any CPU 46 | {93267F8C-80FF-41F0-9316-C3969B81C681}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 47 | {93267F8C-80FF-41F0-9316-C3969B81C681}.Debug|Any CPU.Build.0 = Debug|Any CPU 48 | {93267F8C-80FF-41F0-9316-C3969B81C681}.Release|Any CPU.ActiveCfg = Release|Any CPU 49 | {93267F8C-80FF-41F0-9316-C3969B81C681}.Release|Any CPU.Build.0 = Release|Any CPU 50 | {93D27EB7-BB64-44AB-9B6E-C5071AFF0E48}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 51 | {93D27EB7-BB64-44AB-9B6E-C5071AFF0E48}.Debug|Any CPU.Build.0 = Debug|Any CPU 52 | {93D27EB7-BB64-44AB-9B6E-C5071AFF0E48}.Release|Any CPU.ActiveCfg = Release|Any CPU 53 | {93D27EB7-BB64-44AB-9B6E-C5071AFF0E48}.Release|Any CPU.Build.0 = Release|Any CPU 54 | {B6B07DE4-48AD-4FA1-82AE-50FC10798C86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 55 | {B6B07DE4-48AD-4FA1-82AE-50FC10798C86}.Debug|Any CPU.Build.0 = Debug|Any CPU 56 | {B6B07DE4-48AD-4FA1-82AE-50FC10798C86}.Release|Any CPU.ActiveCfg = Release|Any CPU 57 | {B6B07DE4-48AD-4FA1-82AE-50FC10798C86}.Release|Any CPU.Build.0 = Release|Any CPU 58 | EndGlobalSection 59 | GlobalSection(SolutionProperties) = preSolution 60 | HideSolutionNode = FALSE 61 | EndGlobalSection 62 | GlobalSection(NestedProjects) = preSolution 63 | {45D0FC5B-588C-4A1B-B69E-BC35E26EFD11} = {D234312E-31D1-47BF-B883-DC933726200D} 64 | {6E5FE161-0376-4F28-AA70-3745A44EE028} = {A7C973C5-8F83-4665-AD0B-10A1B6020FDE} 65 | {93267F8C-80FF-41F0-9316-C3969B81C681} = {A7C973C5-8F83-4665-AD0B-10A1B6020FDE} 66 | {93D27EB7-BB64-44AB-9B6E-C5071AFF0E48} = {9D2309C2-3DF8-4338-9A79-C7D894470E5F} 67 | {B6B07DE4-48AD-4FA1-82AE-50FC10798C86} = {9D2309C2-3DF8-4338-9A79-C7D894470E5F} 68 | EndGlobalSection 69 | GlobalSection(ExtensibilityGlobals) = postSolution 70 | SolutionGuid = {53FFB9D1-AB81-43CF-BE4B-E7708ACAA6A5} 71 | EndGlobalSection 72 | EndGlobal 73 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Clean Architecture GraphAPI solution template :sunny: 2 | 3 | ## Description 4 | 5 | Simple Graph API solution template using Dapper ORM for .NET 8 with clean code, clean architecture and CQRS in mind.. 6 | Ideal if you need to set up an Graph API on a existing database. Just install and use the template and start adding queries and mutations. 7 | 8 | ## Technologies 9 | 10 | - [.NET 8](https://github.com/dotnet/core) 11 | - [Dapper](https://github.com/DapperLib/Dapper) 12 | - [HotChocolate](https://github.com/ChilliCream/graphql-platform) 13 | - [FluentValidation](https://github.com/FluentValidation/FluentValidation) 14 | - [Bindicate](https://github.com/Tim-Maes/Bindicate) 15 | 16 | ## Give it a star! :star: 17 | If you have used this template, learned something or like what you see, consider giving it a star! 18 | 19 | ## Installation and Usage :wrench: 20 | 21 | **Install GraphR** 22 | 23 | ```bash 24 | dotnet new --install GraphR 25 | ``` 26 | 27 | **Scaffold your solution** 28 | 29 | Create a folder, for example 'MyNewSolution' and run this command inside the folder: 30 | 31 | ```bash 32 | dotnet new graphr -n MyNewSolution 33 | ``` 34 | The complete solution will be scaffolded inside your folder. Open it in Visual Studio: 35 | 36 | ![image](https://github.com/Tim-Maes/GraphR/assets/91606949/297e227a-4b55-44e0-ab92-4aa3dc5e7558) 37 | 38 | ## Setup :hammer_and_wrench: 39 | 40 | Replace the `connectionString` in `appsettings.json` with your own and remove the `Seed` folder in the `Infrastructure` project. 41 | Remove the example queries/mutation/repositories etc and implement your own. 42 | 43 | ## Implementing Mutation & Query 44 | 45 | In the core layer we have a custom lightweight handler implementation. These are `Handler` for querying data without parameters, 46 | and `Handler` for querying or mutating data with parameters. 47 | Handler is a abstract class so we can leverage the validation method leveraging FluentValidation. 48 | 49 | You still need to define a interface for dependency injection, the handlers are automatically registered as scoped. 50 | 51 | Since we don't use `AutoMapper` to map input types to output types, we just write an extension method `ToOutput()` that maps `TInput` to `ToOutput()`. 52 | 53 | `FluentValidation` is used to validate input parameter properties. 54 | 55 | ### Example 56 | 57 | ```csharp 58 | internal sealed class GetBookByIdQueryHandler : Handler, IGetBookByIdHandler 59 | { 60 | private readonly IBookRepository _bookRepository; 61 | 62 | public GetBookByIdQueryHandler(IBookRepository bookRepository) 63 | { 64 | _bookRepository = bookRepository; 65 | } 66 | 67 | protected override void DefineRules() 68 | { 69 | RuleFor(x => x.Id).GreaterThan(0); 70 | } 71 | 72 | protected override async Task HandleValidatedRequest(GetBookByIdParameters request) 73 | => (await _bookRepository.GetById(request.Id)).ToOutput(); 74 | } 75 | 76 | public interface IGetBookByIdHandler : IHandler { } 77 | ``` 78 | 79 | Inject the `IGetBookByIdQueryHandler` in your GraphApi query using the HotChocolate `[Service]` attribute, do the same for Mutations. 80 | 81 | ```csharp 82 | public sealed class BooksQuery 83 | { 84 | public async Task Book([Service] IGetBookByIdHandler handler, GetBookByIdParameters parameters) 85 | => await handler.Handle(parameters); 86 | } 87 | ``` 88 | 89 | This is an example of how your GraphApi application layer could be structured 90 | ![image](https://github.com/Tim-Maes/GraphR/assets/91606949/3384b79a-0b3e-4587-82a5-ffe579731715) 91 | 92 | 93 | ## Database :file_cabinet: 94 | 95 | Currently supports a `DbConnectionProvider` for a single SQL database connection. Inject the `IDbConnectionProvider` in your repositories. 96 | 97 | ### Transactions 98 | 99 | In the domain folder there is a abstraction of the `DbTransaction` implementation. You can inject the `ITransaction` interface in a `MutationHandler` in your Application layer if you need to mutate data over multiple repositories. 100 | 101 | ```csharp 102 | internal class ExampleMutationHandler : Handler, 103 | IExampleMutationHandler 104 | { 105 | private readonly IRepository _repository; 106 | private readonly ISecondRepository _secondRepository; 107 | private readonly ITransaction _transaction; 108 | 109 | public ExampleMutationHandler( 110 | IRepository secondRepository, 111 | ISecondRepository secondRepository, 112 | ITransaction transaction) 113 | { 114 | _repository = repository; 115 | _secondRepository = secondRepository; 116 | _transaction = transaction; 117 | } 118 | 119 | protected override void DefineRules() 120 | { 121 | // FluentValidation RuleSet for your input 122 | } 123 | 124 | protected override async Task HandleValidatedRequest(ExampleMutationParameters input) 125 | { 126 | _transaction.Begin() 127 | try 128 | { 129 | await _repository.Create(...); 130 | 131 | await _secondRepository.UpdateSomething( ... ); 132 | 133 | _transaction.Commit(); 134 | } 135 | catch 136 | { 137 | _transaction.RollBack(); 138 | throw; 139 | } 140 | 141 | return new Result(...); 142 | } 143 | } 144 | 145 | public interface IExampleMutationHandler : IHandler { } 146 | ``` 147 | 148 | ## Architecture overview :spiral_notepad: 149 | 150 | ### WebApi 151 | 152 | A .NET 8 WebAPI application, here we have our GraphAPI endpoint. This application depends on the Application layer, and it also has a reference to the Infrastructure layer to wire up the IoC container (dependency injection), so we only use it in the `ServiceCollectionExtensions`. 153 | 154 | ### Application 155 | 156 | This layer contains all application logic and it depends only on the Domain and Core layer. Here we implement the handlers, graphApi input and output types, queries and mutations. 157 | 158 | ### Domain 159 | 160 | This will contain all models, enums, exceptions, interfaces, types and logic specific to the domain layer. This project references no other project. 161 | 162 | ### Infrastructure 163 | 164 | In this layer we implement the data access (repositories, Dapper implementation, EntityMaps..) and possibly classes to access other external resources. These classes should be based on interfaces defined within the application layer. 165 | 166 | ### Core 167 | 168 | This project holds some core logic that we need in our solution. In the template, we have logic that wires up the custom handler system and the method to register Dapper `IEntityMap` registrations. 169 | 170 | ## Autowiring 171 | 172 | This project uses the `Bindicate` library to autowire dependencies by using attributes, so we don't bloat the `ServiceCollectionExtensions`. 173 | 174 | 175 | ## Test the API 176 | 177 | Build and run the project, and navigate to /graphql, this will take you to the Banana Cake Pop playground where you can find the graphql schema: 178 | 179 | ![image](https://github.com/Tim-Maes/GraphR/assets/91606949/5b8bdfb1-74fc-4e54-a8a9-e72cacd4845c) 180 | 181 | You can play around in the Banana Cake Pop playground and test out a query. 182 | 183 | For example: 184 | 185 | ![image](https://github.com/Tim-Maes/GraphR/assets/91606949/57b26947-86e0-4c5f-b74a-ea92520b7d31) 186 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Oo]ut/ 33 | [Ll]og/ 34 | [Ll]ogs/ 35 | 36 | # Visual Studio 2015/2017 cache/options directory 37 | .vs/ 38 | # Uncomment if you have tasks that create the project's static files in wwwroot 39 | #wwwroot/ 40 | 41 | # Visual Studio 2017 auto generated files 42 | Generated\ Files/ 43 | 44 | # MSTest test Results 45 | [Tt]est[Rr]esult*/ 46 | [Bb]uild[Ll]og.* 47 | 48 | # NUnit 49 | *.VisualState.xml 50 | TestResult.xml 51 | nunit-*.xml 52 | 53 | # Build Results of an ATL Project 54 | [Dd]ebugPS/ 55 | [Rr]eleasePS/ 56 | dlldata.c 57 | 58 | # Benchmark Results 59 | BenchmarkDotNet.Artifacts/ 60 | 61 | # .NET Core 62 | project.lock.json 63 | project.fragment.lock.json 64 | artifacts/ 65 | 66 | # ASP.NET Scaffolding 67 | ScaffoldingReadMe.txt 68 | 69 | # StyleCop 70 | StyleCopReport.xml 71 | 72 | # Files built by Visual Studio 73 | *_i.c 74 | *_p.c 75 | *_h.h 76 | *.ilk 77 | *.meta 78 | *.obj 79 | *.iobj 80 | *.pch 81 | *.pdb 82 | *.ipdb 83 | *.pgc 84 | *.pgd 85 | *.rsp 86 | *.sbr 87 | *.tlb 88 | *.tli 89 | *.tlh 90 | *.tmp 91 | *.tmp_proj 92 | *_wpftmp.csproj 93 | *.log 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio LightSwitch build output 298 | **/*.HTMLClient/GeneratedArtifacts 299 | **/*.DesktopClient/GeneratedArtifacts 300 | **/*.DesktopClient/ModelManifest.xml 301 | **/*.Server/GeneratedArtifacts 302 | **/*.Server/ModelManifest.xml 303 | _Pvt_Extensions 304 | 305 | # Paket dependency manager 306 | .paket/paket.exe 307 | paket-files/ 308 | 309 | # FAKE - F# Make 310 | .fake/ 311 | 312 | # CodeRush personal settings 313 | .cr/personal 314 | 315 | # Python Tools for Visual Studio (PTVS) 316 | __pycache__/ 317 | *.pyc 318 | 319 | # Cake - Uncomment if you are using it 320 | # tools/** 321 | # !tools/packages.config 322 | 323 | # Tabs Studio 324 | *.tss 325 | 326 | # Telerik's JustMock configuration file 327 | *.jmconfig 328 | 329 | # BizTalk build output 330 | *.btp.cs 331 | *.btm.cs 332 | *.odx.cs 333 | *.xsd.cs 334 | 335 | # OpenCover UI analysis results 336 | OpenCover/ 337 | 338 | # Azure Stream Analytics local run output 339 | ASALocalRun/ 340 | 341 | # MSBuild Binary and Structured Log 342 | *.binlog 343 | 344 | # NVidia Nsight GPU debugger configuration file 345 | *.nvuser 346 | 347 | # MFractors (Xamarin productivity tool) working folder 348 | .mfractor/ 349 | 350 | # Local History for Visual Studio 351 | .localhistory/ 352 | 353 | # BeatPulse healthcheck temp database 354 | healthchecksdb 355 | 356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 357 | MigrationBackup/ 358 | 359 | # Ionide (cross platform F# VS Code tools) working folder 360 | .ionide/ 361 | 362 | # Fody - auto-generated XML schema 363 | FodyWeavers.xsd -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | charset = utf-8 6 | trim_trailing_whitespace = true 7 | insert_final_newline = true 8 | 9 | [*.cs] 10 | indent_size = 4 11 | dotnet_sort_system_directives_first = true 12 | 13 | # Don't use this. qualifier 14 | dotnet_style_qualification_for_field = false:suggestion 15 | dotnet_style_qualification_for_property = false:suggestion 16 | 17 | # use int x = .. over Int32 18 | dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion 19 | 20 | # use int.MaxValue over Int32.MaxValue 21 | dotnet_style_predefined_type_for_member_access = true:suggestion 22 | 23 | # Require var all the time. 24 | csharp_style_var_for_built_in_types = true:suggestion 25 | csharp_style_var_when_type_is_apparent = true:suggestion 26 | csharp_style_var_elsewhere = true:suggestion 27 | 28 | # Disallow throw expressions. 29 | csharp_style_throw_expression = false:suggestion 30 | 31 | # Newline settings 32 | csharp_new_line_before_open_brace = all 33 | csharp_new_line_before_else = true 34 | csharp_new_line_before_catch = true 35 | csharp_new_line_before_finally = true 36 | csharp_new_line_before_members_in_object_initializers = true 37 | csharp_new_line_before_members_in_anonymous_types = true 38 | 39 | # Namespace settings 40 | csharp_style_namespace_declarations = file_scoped 41 | 42 | # Brace settings 43 | csharp_prefer_braces = true # Prefer curly braces even for one line of code 44 | 45 | # name all constant fields using PascalCase 46 | dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion 47 | dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields 48 | dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style 49 | dotnet_naming_symbols.constant_fields.applicable_kinds = field 50 | dotnet_naming_symbols.constant_fields.required_modifiers = const 51 | dotnet_naming_style.pascal_case_style.capitalization = pascal_case 52 | 53 | # internal and private fields should be _camelCase 54 | dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion 55 | dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields 56 | dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style 57 | dotnet_naming_symbols.private_internal_fields.applicable_kinds = field 58 | dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal 59 | dotnet_naming_style.camel_case_underscore_style.required_prefix = _ 60 | dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case 61 | 62 | [*.{xml,config,*proj,nuspec,props,resx,targets,yml,tasks}] 63 | indent_size = 2 64 | 65 | # Xml config files 66 | [*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}] 67 | indent_size = 2 68 | 69 | [*.json] 70 | indent_size = 2 71 | 72 | [*.{ps1,psm1}] 73 | indent_size = 4 74 | 75 | [*.sh] 76 | indent_size = 4 77 | end_of_line = lf 78 | 79 | [*.{razor,cshtml}] 80 | charset = utf-8-bom 81 | 82 | [*.{cs,vb}] 83 | 84 | # SYSLIB1054: Use 'LibraryImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time 85 | dotnet_diagnostic.SYSLIB1054.severity = warning 86 | 87 | # CA1018: Mark attributes with AttributeUsageAttribute 88 | dotnet_diagnostic.CA1018.severity = warning 89 | 90 | # CA1047: Do not declare protected member in sealed type 91 | dotnet_diagnostic.CA1047.severity = warning 92 | 93 | # CA1305: Specify IFormatProvider 94 | dotnet_diagnostic.CA1305.severity = warning 95 | 96 | # CA1507: Use nameof to express symbol names 97 | dotnet_diagnostic.CA1507.severity = warning 98 | 99 | # CA1510: Use ArgumentNullException throw helper 100 | dotnet_diagnostic.CA1510.severity = warning 101 | 102 | # CA1511: Use ArgumentException throw helper 103 | dotnet_diagnostic.CA1511.severity = warning 104 | 105 | # CA1512: Use ArgumentOutOfRangeException throw helper 106 | dotnet_diagnostic.CA1512.severity = warning 107 | 108 | # CA1513: Use ObjectDisposedException throw helper 109 | dotnet_diagnostic.CA1513.severity = warning 110 | 111 | # CA1725: Parameter names should match base declaration 112 | dotnet_diagnostic.CA1725.severity = suggestion 113 | 114 | # CA1802: Use literals where appropriate 115 | dotnet_diagnostic.CA1802.severity = warning 116 | 117 | # CA1805: Do not initialize unnecessarily 118 | dotnet_diagnostic.CA1805.severity = warning 119 | 120 | # CA1810: Do not initialize unnecessarily 121 | dotnet_diagnostic.CA1810.severity = warning 122 | 123 | # CA1821: Remove empty Finalizers 124 | dotnet_diagnostic.CA1821.severity = warning 125 | 126 | # CA1822: Make member static 127 | dotnet_diagnostic.CA1822.severity = warning 128 | dotnet_code_quality.CA1822.api_surface = private, internal 129 | 130 | # CA1823: Avoid unused private fields 131 | dotnet_diagnostic.CA1823.severity = warning 132 | 133 | # CA1825: Avoid zero-length array allocations 134 | dotnet_diagnostic.CA1825.severity = warning 135 | 136 | # CA1826: Do not use Enumerable methods on indexable collections. Instead use the collection directly 137 | dotnet_diagnostic.CA1826.severity = warning 138 | 139 | # CA1827: Do not use Count() or LongCount() when Any() can be used 140 | dotnet_diagnostic.CA1827.severity = warning 141 | 142 | # CA1828: Do not use CountAsync() or LongCountAsync() when AnyAsync() can be used 143 | dotnet_diagnostic.CA1828.severity = warning 144 | 145 | # CA1829: Use Length/Count property instead of Count() when available 146 | dotnet_diagnostic.CA1829.severity = warning 147 | 148 | # CA1830: Prefer strongly-typed Append and Insert method overloads on StringBuilder 149 | dotnet_diagnostic.CA1830.severity = warning 150 | 151 | # CA1831: Use AsSpan or AsMemory instead of Range-based indexers when appropriate 152 | dotnet_diagnostic.CA1831.severity = warning 153 | 154 | # CA1832: Use AsSpan or AsMemory instead of Range-based indexers when appropriate 155 | dotnet_diagnostic.CA1832.severity = warning 156 | 157 | # CA1833: Use AsSpan or AsMemory instead of Range-based indexers when appropriate 158 | dotnet_diagnostic.CA1833.severity = warning 159 | 160 | # CA1834: Consider using 'StringBuilder.Append(char)' when applicable 161 | dotnet_diagnostic.CA1834.severity = warning 162 | 163 | # CA1835: Prefer the 'Memory'-based overloads for 'ReadAsync' and 'WriteAsync' 164 | dotnet_diagnostic.CA1835.severity = warning 165 | 166 | # CA1836: Prefer IsEmpty over Count 167 | dotnet_diagnostic.CA1836.severity = warning 168 | 169 | # CA1837: Use 'Environment.ProcessId' 170 | dotnet_diagnostic.CA1837.severity = warning 171 | 172 | # CA1838: Avoid 'StringBuilder' parameters for P/Invokes 173 | dotnet_diagnostic.CA1838.severity = warning 174 | 175 | # CA1839: Use 'Environment.ProcessPath' 176 | dotnet_diagnostic.CA1839.severity = warning 177 | 178 | # CA1840: Use 'Environment.CurrentManagedThreadId' 179 | dotnet_diagnostic.CA1840.severity = warning 180 | 181 | # CA1841: Prefer Dictionary.Contains methods 182 | dotnet_diagnostic.CA1841.severity = warning 183 | 184 | # CA1842: Do not use 'WhenAll' with a single task 185 | dotnet_diagnostic.CA1842.severity = warning 186 | 187 | # CA1843: Do not use 'WaitAll' with a single task 188 | dotnet_diagnostic.CA1843.severity = warning 189 | 190 | # CA1844: Provide memory-based overrides of async methods when subclassing 'Stream' 191 | dotnet_diagnostic.CA1844.severity = warning 192 | 193 | # CA1845: Use span-based 'string.Concat' 194 | dotnet_diagnostic.CA1845.severity = warning 195 | 196 | # CA1846: Prefer AsSpan over Substring 197 | dotnet_diagnostic.CA1846.severity = warning 198 | 199 | # CA1847: Use string.Contains(char) instead of string.Contains(string) with single characters 200 | dotnet_diagnostic.CA1847.severity = warning 201 | 202 | # CA1852: Seal internal types 203 | dotnet_diagnostic.CA1852.severity = warning 204 | 205 | # CA1854: Prefer the IDictionary.TryGetValue(TKey, out TValue) method 206 | dotnet_diagnostic.CA1854.severity = warning 207 | 208 | # CA1855: Prefer 'Clear' over 'Fill' 209 | dotnet_diagnostic.CA1855.severity = warning 210 | 211 | # CA1856: Incorrect usage of ConstantExpected attribute 212 | dotnet_diagnostic.CA1856.severity = error 213 | 214 | # CA1857: A constant is expected for the parameter 215 | dotnet_diagnostic.CA1857.severity = warning 216 | 217 | # CA1858: Use 'StartsWith' instead of 'IndexOf' 218 | dotnet_diagnostic.CA1858.severity = warning 219 | 220 | # CA2007: Consider calling ConfigureAwait on the awaited task 221 | dotnet_diagnostic.CA2007.severity = warning 222 | 223 | # CA2008: Do not create tasks without passing a TaskScheduler 224 | dotnet_diagnostic.CA2008.severity = warning 225 | 226 | # CA2009: Do not call ToImmutableCollection on an ImmutableCollection value 227 | dotnet_diagnostic.CA2009.severity = warning 228 | 229 | # CA2011: Avoid infinite recursion 230 | dotnet_diagnostic.CA2011.severity = warning 231 | 232 | # CA2012: Use ValueTask correctly 233 | dotnet_diagnostic.CA2012.severity = warning 234 | 235 | # CA2013: Do not use ReferenceEquals with value types 236 | dotnet_diagnostic.CA2013.severity = warning 237 | 238 | # CA2014: Do not use stackalloc in loops. 239 | dotnet_diagnostic.CA2014.severity = warning 240 | 241 | # CA2016: Forward the 'CancellationToken' parameter to methods that take one 242 | dotnet_diagnostic.CA2016.severity = warning 243 | 244 | # CA2200: Rethrow to preserve stack details 245 | dotnet_diagnostic.CA2200.severity = warning 246 | 247 | # CA2201: Do not raise reserved exception types 248 | dotnet_diagnostic.CA2201.severity = warning 249 | 250 | # CA2208: Instantiate argument exceptions correctly 251 | dotnet_diagnostic.CA2208.severity = warning 252 | 253 | # CA2245: Do not assign a property to itself 254 | dotnet_diagnostic.CA2245.severity = warning 255 | 256 | # CA2246: Assigning symbol and its member in the same statement 257 | dotnet_diagnostic.CA2246.severity = warning 258 | 259 | # CA2249: Use string.Contains instead of string.IndexOf to improve readability. 260 | dotnet_diagnostic.CA2249.severity = warning 261 | 262 | # IDE0005: Remove unnecessary usings 263 | dotnet_diagnostic.IDE0005.severity = warning 264 | 265 | # IDE0011: Curly braces to surround blocks of code 266 | dotnet_diagnostic.IDE0011.severity = warning 267 | 268 | # IDE0020: Use pattern matching to avoid is check followed by a cast (with variable) 269 | dotnet_diagnostic.IDE0020.severity = warning 270 | 271 | # IDE0029: Use coalesce expression (non-nullable types) 272 | dotnet_diagnostic.IDE0029.severity = warning 273 | 274 | # IDE0030: Use coalesce expression (nullable types) 275 | dotnet_diagnostic.IDE0030.severity = warning 276 | 277 | # IDE0031: Use null propagation 278 | dotnet_diagnostic.IDE0031.severity = warning 279 | 280 | # IDE0035: Remove unreachable code 281 | dotnet_diagnostic.IDE0035.severity = warning 282 | 283 | # IDE0036: Order modifiers 284 | csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion 285 | dotnet_diagnostic.IDE0036.severity = warning 286 | 287 | # IDE0038: Use pattern matching to avoid is check followed by a cast (without variable) 288 | dotnet_diagnostic.IDE0038.severity = warning 289 | 290 | # IDE0043: Format string contains invalid placeholder 291 | dotnet_diagnostic.IDE0043.severity = warning 292 | 293 | # IDE0044: Make field readonly 294 | dotnet_diagnostic.IDE0044.severity = warning 295 | 296 | # IDE0051: Remove unused private members 297 | dotnet_diagnostic.IDE0051.severity = warning 298 | 299 | # IDE0055: All formatting rules 300 | dotnet_diagnostic.IDE0055.severity = suggestion 301 | 302 | # IDE0059: Unnecessary assignment to a value 303 | dotnet_diagnostic.IDE0059.severity = warning 304 | 305 | # IDE0060: Remove unused parameter 306 | dotnet_code_quality_unused_parameters = non_public 307 | dotnet_diagnostic.IDE0060.severity = warning 308 | 309 | # IDE0062: Make local function static 310 | dotnet_diagnostic.IDE0062.severity = warning 311 | 312 | # IDE0161: Convert to file-scoped namespace 313 | dotnet_diagnostic.IDE0161.severity = warning 314 | 315 | # IDE0200: Lambda expression can be removed 316 | dotnet_diagnostic.IDE0200.severity = warning 317 | 318 | # IDE2000: Disallow multiple blank lines 319 | dotnet_style_allow_multiple_blank_lines_experimental = false 320 | dotnet_diagnostic.IDE2000.severity = warning 321 | 322 | [{eng/tools/**.cs,**/{test,testassets,samples,Samples,perf,benchmarkapps,scripts,stress}/**.cs,src/Hosting/Server.IntegrationTesting/**.cs,src/Servers/IIS/IntegrationTesting.IIS/**.cs,src/Shared/Http2cat/**.cs,src/Testing/**.cs}] 323 | # CA1018: Mark attributes with AttributeUsageAttribute 324 | dotnet_diagnostic.CA1018.severity = suggestion 325 | # CA1507: Use nameof to express symbol names 326 | dotnet_diagnostic.CA1507.severity = suggestion 327 | # CA1510: Use ArgumentNullException throw helper 328 | dotnet_diagnostic.CA1510.severity = suggestion 329 | # CA1511: Use ArgumentException throw helper 330 | dotnet_diagnostic.CA1511.severity = suggestion 331 | # CA1512: Use ArgumentOutOfRangeException throw helper 332 | dotnet_diagnostic.CA1512.severity = suggestion 333 | # CA1513: Use ObjectDisposedException throw helper 334 | dotnet_diagnostic.CA1513.severity = suggestion 335 | # CA1802: Use literals where appropriate 336 | dotnet_diagnostic.CA1802.severity = suggestion 337 | # CA1805: Do not initialize unnecessarily 338 | dotnet_diagnostic.CA1805.severity = suggestion 339 | # CA1810: Do not initialize unnecessarily 340 | dotnet_diagnostic.CA1810.severity = suggestion 341 | # CA1822: Make member static 342 | dotnet_diagnostic.CA1822.severity = suggestion 343 | # CA1823: Avoid zero-length array allocations 344 | dotnet_diagnostic.CA1825.severity = suggestion 345 | # CA1826: Do not use Enumerable methods on indexable collections. Instead use the collection directly 346 | dotnet_diagnostic.CA1826.severity = suggestion 347 | # CA1827: Do not use Count() or LongCount() when Any() can be used 348 | dotnet_diagnostic.CA1827.severity = suggestion 349 | # CA1829: Use Length/Count property instead of Count() when available 350 | dotnet_diagnostic.CA1829.severity = suggestion 351 | # CA1831: Use AsSpan or AsMemory instead of Range-based indexers when appropriate 352 | dotnet_diagnostic.CA1831.severity = suggestion 353 | # CA1832: Use AsSpan or AsMemory instead of Range-based indexers when appropriate 354 | dotnet_diagnostic.CA1832.severity = suggestion 355 | # CA1833: Use AsSpan or AsMemory instead of Range-based indexers when appropriate 356 | dotnet_diagnostic.CA1833.severity = suggestion 357 | # CA1834: Consider using 'StringBuilder.Append(char)' when applicable 358 | dotnet_diagnostic.CA1834.severity = suggestion 359 | # CA1835: Prefer the 'Memory'-based overloads for 'ReadAsync' and 'WriteAsync' 360 | dotnet_diagnostic.CA1835.severity = suggestion 361 | # CA1837: Use 'Environment.ProcessId' 362 | dotnet_diagnostic.CA1837.severity = suggestion 363 | # CA1838: Avoid 'StringBuilder' parameters for P/Invokes 364 | dotnet_diagnostic.CA1838.severity = suggestion 365 | # CA1841: Prefer Dictionary.Contains methods 366 | dotnet_diagnostic.CA1841.severity = suggestion 367 | # CA1844: Provide memory-based overrides of async methods when subclassing 'Stream' 368 | dotnet_diagnostic.CA1844.severity = suggestion 369 | # CA1845: Use span-based 'string.Concat' 370 | dotnet_diagnostic.CA1845.severity = suggestion 371 | # CA1846: Prefer AsSpan over Substring 372 | dotnet_diagnostic.CA1846.severity = suggestion 373 | # CA1847: Use string.Contains(char) instead of string.Contains(string) with single characters 374 | dotnet_diagnostic.CA1847.severity = suggestion 375 | # CA1852: Seal internal types 376 | dotnet_diagnostic.CA1852.severity = suggestion 377 | # CA1854: Prefer the IDictionary.TryGetValue(TKey, out TValue) method 378 | dotnet_diagnostic.CA1854.severity = suggestion 379 | # CA1855: Prefer 'Clear' over 'Fill' 380 | dotnet_diagnostic.CA1855.severity = suggestion 381 | # CA1856: Incorrect usage of ConstantExpected attribute 382 | dotnet_diagnostic.CA1856.severity = suggestion 383 | # CA1857: A constant is expected for the parameter 384 | dotnet_diagnostic.CA1857.severity = suggestion 385 | # CA1858: Use 'StartsWith' instead of 'IndexOf' 386 | dotnet_diagnostic.CA1858.severity = suggestion 387 | # CA2007: Consider calling ConfigureAwait on the awaited task 388 | dotnet_diagnostic.CA2007.severity = suggestion 389 | # CA2008: Do not create tasks without passing a TaskScheduler 390 | dotnet_diagnostic.CA2008.severity = suggestion 391 | # CA2012: Use ValueTask correctly 392 | dotnet_diagnostic.CA2012.severity = suggestion 393 | # CA2201: Do not raise reserved exception types 394 | dotnet_diagnostic.CA2201.severity = suggestion 395 | # CA2249: Use string.Contains instead of string.IndexOf to improve readability. 396 | dotnet_diagnostic.CA2249.severity = suggestion 397 | # IDE0005: Remove unnecessary usings 398 | dotnet_diagnostic.IDE0005.severity = suggestion 399 | # IDE0020: Use pattern matching to avoid is check followed by a cast (with variable) 400 | dotnet_diagnostic.IDE0020.severity = suggestion 401 | # IDE0029: Use coalesce expression (non-nullable types) 402 | dotnet_diagnostic.IDE0029.severity = suggestion 403 | # IDE0030: Use coalesce expression (nullable types) 404 | dotnet_diagnostic.IDE0030.severity = suggestion 405 | # IDE0031: Use null propagation 406 | dotnet_diagnostic.IDE0031.severity = suggestion 407 | # IDE0038: Use pattern matching to avoid is check followed by a cast (without variable) 408 | dotnet_diagnostic.IDE0038.severity = suggestion 409 | # IDE0044: Make field readonly 410 | dotnet_diagnostic.IDE0044.severity = suggestion 411 | # IDE0051: Remove unused private members 412 | dotnet_diagnostic.IDE0051.severity = suggestion 413 | # IDE0059: Unnecessary assignment to a value 414 | dotnet_diagnostic.IDE0059.severity = suggestion 415 | # IDE0060: Remove unused parameters 416 | dotnet_diagnostic.IDE0060.severity = suggestion 417 | # IDE0062: Make local function static 418 | dotnet_diagnostic.IDE0062.severity = suggestion 419 | # IDE0200: Lambda expression can be removed 420 | dotnet_diagnostic.IDE0200.severity = suggestion 421 | 422 | # CA2016: Forward the 'CancellationToken' parameter to methods that take one 423 | dotnet_diagnostic.CA2016.severity = suggestion 424 | 425 | # Defaults for content in the shared src/ and shared runtime dir 426 | 427 | [{**/Shared/runtime/**.{cs,vb},src/Shared/test/Shared.Tests/runtime/**.{cs,vb},**/microsoft.extensions.hostfactoryresolver.sources/**.{cs,vb}}] 428 | # CA1822: Make member static 429 | dotnet_diagnostic.CA1822.severity = silent 430 | # IDE0011: Use braces 431 | dotnet_diagnostic.IDE0011.severity = silent 432 | # IDE0055: Fix formatting 433 | dotnet_diagnostic.IDE0055.severity = silent 434 | # IDE0060: Remove unused parameters 435 | dotnet_diagnostic.IDE0060.severity = silent 436 | # IDE0062: Make local function static 437 | dotnet_diagnostic.IDE0062.severity = silent 438 | # IDE0161: Convert to file-scoped namespace 439 | dotnet_diagnostic.IDE0161.severity = silent 440 | 441 | [{**/Shared/**.cs,**/microsoft.extensions.hostfactoryresolver.sources/**.{cs,vb}}] 442 | # IDE0005: Remove unused usings. Ignore for shared src files since imports for those depend on the projects in which they are included. 443 | dotnet_diagnostic.IDE0005.severity = silent 444 | --------------------------------------------------------------------------------