Skip to content

Source Generator Improvement Proposal#31

Open
Seeker1437 wants to merge 1 commit intoTheEightBot:developfrom
Seeker1437:feature/source-generator
Open

Source Generator Improvement Proposal#31
Seeker1437 wants to merge 1 commit intoTheEightBot:developfrom
Seeker1437:feature/source-generator

Conversation

@Seeker1437
Copy link
Contributor

Contains changes I meant to PR before parting ways.

Add support for explicit service types, open generics, and keyed service registration

Register as self, singleton

[ServiceRegistration(Lifetime.Singleton)]
public class MyService { }

Register as interface, scoped

[ServiceRegistration(Lifetime.Scoped, registerInterfaces: true)]
public class MyService : IMyService { }

Register explicit interface, scoped

[ServiceRegistration(Lifetime.Scoped, ServiceType = typeof(IMyService))]
public class MyService : IMyService { }

Register open generic repository as IRepository, scoped

[ServiceRegistration(Lifetime.Scoped, ServiceType = typeof(IRepository<>))]
public class Repository<T> : IRepository<T> { }

Register keyed service (Vip) as IDiscountService

[ServiceRegistration(
    Lifetime.Singleton,
    ServiceType = typeof(IDiscountService),
    Key = "Vip")]
public class VipDiscountService : IDiscountService { }

Register the same implementation under multiple keys

[ServiceRegistration(Lifetime.Singleton, ServiceType = typeof(IDiscountService), Key = "Basic")]
[ServiceRegistration(Lifetime.Singleton, ServiceType = typeof(IDiscountService), Key = "Premium")]
public class DiscountService : IDiscountService { }

Contains changes I meant to PR before parting ways.

Add support for explicit service types, open generics, and keyed service registration
@Seeker1437 Seeker1437 changed the base branch from main to develop December 28, 2025 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant