Public Register() + new Configure()#2
Merged
dustinsoftware merged 4 commits intodustinsoftware:mainfrom Apr 1, 2025
Merged
Conversation
dustinsoftware
approved these changes
Apr 1, 2025
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Populate()isn't meant to be called more than once because it addsIServiceProviderand such, but for migration purposes it would be useful to be able to register additional collections of services.After more tinkering, I also propose a new
Configure()method to support the commonIServiceCollection AddWhatever(this IServiceCollection services)pattern.A
Registrymigration could look like this:public class MyRegistry : Registry { - public MyRegistry() + public MyRegistry() => this.Configure(Register); + + public static IServiceCollection Register(IServiceCollection services) { - For<IService>().Singleton().Use<Service>(); + services.AddSingleton<IService, Service>(); // … + return services; } }Include<MyRegistry>()will continue to work, but parent registries can migrate incrementally:public class MyParentRegistry : Registry { public MyParentRegistry() { - IncludeRegistry<MyRegistry>(); + this.Configure(MyRegistry.Register); IncludeRegistry<MyOtherRegistry>(); } }I also included a
Configure(this IServiceCollection)to allow these non-extension methods to play nicely untilRegistrysupport is no longer required and the class can be madestatic, e.g.