Categories
Categories
Section titled “Categories”Categories solve the problem of needing different service registrations for different environments. Tag services with a category, and they’re only registered when that category is activated:
[Singleton(Category = "Test")]public class MockPaymentService : IPaymentService;
[Singleton(Category = "Production")]public class StripePaymentService : IPaymentService;// Production startup — registers all uncategorized services + "Production" tagged servicesbuilder.Services.AddShinyServiceRegistry("Production");
// Test startup — registers all uncategorized services + "Test" tagged servicesservices.AddShinyServiceRegistry("Test");
// Multiple categoriesservices.AddShinyServiceRegistry("Production", "Analytics");Helper Extensions
Section titled “Helper Extensions”Additional extension methods on IServiceCollection:
// Register against all implemented interfacesservices.AddSingletonAsImplementedInterfaces<MyService>();services.AddScopedAsImplementedInterfaces<MyService>();
// Keyed variantservices.AddSingletonAsImplementedInterfaces<MyService>("keyName");
// Check registrationsbool hasService = services.HasService<IMyService>();bool hasImpl = services.HasImplementation<MyService>();
// Lazy resolutionLazy<IMyService> lazy = services.GetLazyService<IMyService>(required: true);