Skip to content

Conversation

@dahlbyk
Copy link
Collaborator

@dahlbyk dahlbyk commented Mar 29, 2025

Populate() isn't meant to be called more than once because it adds IServiceProvider and 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 common IServiceCollection AddWhatever(this IServiceCollection services) pattern.

A Registry migration 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 until Registry support is no longer required and the class can be made static, e.g.

services
    .AddStuff()
    .Configure(MyRegistry.Register)
    .AddMoreStuff();

@dahlbyk dahlbyk changed the title Public Register() Public Register() + new Configure() Mar 29, 2025
@dustinsoftware dustinsoftware merged commit 957098b into dustinsoftware:main Apr 1, 2025
1 check failed
@dahlbyk dahlbyk deleted the public-Register branch April 6, 2025 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants