Created
March 2, 2021 07:26
-
-
Save danielplawgo/c359d85dc3f9e402224d2161a1783f4c to your computer and use it in GitHub Desktop.
Scrutor auto rejestracja typów
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IRepository | |
{ | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface ICategoryRepository : IRepository | |
{ | |
Category GetById(Guid id); | |
} | |
public class CategoryRepository : ICategoryRepository | |
{ | |
public Category GetById(Guid id) | |
{ | |
return new Category() | |
{ | |
Id = id | |
}; | |
} | |
} | |
public interface IProductRepository : IRepository | |
{ | |
Product GetById(Guid id); | |
} | |
public class ProductRepository : IProductRepository | |
{ | |
public Product GetById(Guid id) | |
{ | |
return new Product() | |
{ | |
Id = id | |
}; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class ServiceCollectionExtensions | |
{ | |
public static IServiceCollection AddRepositories(this IServiceCollection services) | |
{ | |
services.Scan(s => s.FromAssemblyOf<IRepository>() | |
.AddClasses(c => c.AssignableTo<IRepository>()) | |
.AsImplementedInterfaces() | |
.WithScopedLifetime()); | |
return services; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddScoped<IProductRepository, ProductRepository>(); | |
services.AddScoped<ICategoryRepository, CategoryRepository>(); | |
services.AddControllers(); | |
services.AddSwaggerGen(c => | |
{ | |
c.SwaggerDoc("v1", new OpenApiInfo { Title = "ScrutorTests", Version = "v1" }); | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.Scan(s => s.FromAssemblyOf<IRepository>() | |
.AddClasses(c => c.AssignableTo<IRepository>()) | |
.AsImplementedInterfaces() | |
.WithScopedLifetime()); | |
services.AddControllers(); | |
services.AddSwaggerGen(c => | |
{ | |
c.SwaggerDoc("v1", new OpenApiInfo { Title = "ScrutorTests", Version = "v1" }); | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddRepositories(); | |
services.AddControllers(); | |
services.AddSwaggerGen(c => | |
{ | |
c.SwaggerDoc("v1", new OpenApiInfo { Title = "ScrutorTests", Version = "v1" }); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment