ServiceCollector is a .NET library that provides utilities for service discovery and validation within your .NET applications.
You can install the ServiceCollector package via NuGet Package Manager Console or through the NuGet Package Manager UI in Visual Studio.
Install-Package ServiceCollector.Core
Search for "ServiceCollector.Core" in the NuGet Package Manager UI, then click "Install."
create one class that implemented IServiceDiscovery(class name is not important) :
public class ServiceManager : IServiceDiscovery { public void AddServices(IServiceCollection serviceCollection) { serviceCollection.AddScoped(); serviceCollection.AddTransient(); serviceCollection.AddSingleton(); // add other services } }
you can create many classes that implemented IServiceDiscovery all of them detected and apply services in program.
Service discovery allows you to automatically discover and add services to the service collection from specified assemblies.
using ServiceCollector.Core; var builder = WebApplication.CreateBuilder(args); builder.Services.AddServiceDiscovery(); var app = builder.Build(); app.Run();
Service validation allows you to validate services based on certain conditions, such as naming conventions.
install package :
Install-Package ServiceCollector.Validation
this validator check that all of the services register in DI,if one service meet the condition but not register validator detect it and throw exception
using ServiceCollector.Core; var builder = WebApplication.CreateBuilder(args); builder.Services.AddServiceDiscovery() .ValidationSetting() .WithStartName("Prefix") .WithEndName("Suffix") .Validate(); var app = builder.Build(); app.Run();
if you want write any test(UnitTest,IntegrationTest) you need some test-doubles
install package :
Install-Package ServiceCollector.Mock
you can easily mock all services and use it in your tests:
public void X_X_X() { // Arrange// you can set any classes that implemented IServiceDiscovery var serviceType = typeof(ServiceManager); // create a mock for each service that defined in ServiceManager var mockResult = Mock.MockCollection(serviceType); // Act // Assert
}
Debugging without relying on external services and facilitating rapid service delivery to front-end developers without the need for implementation.
install packages :
Install-Package ServiceCollector.Fake
ServiceCollector.Abstractions
ServiceCollector.Core
ServiceCollector.Validation
ServiceCollector.Mock
ServiceCollector.Fake
ServiceCollector.Fake.Configuration
This project is licensed under the MIT License