-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
generate extension-method for registering generated classes with Microsoft.Extensions.DependencyInjection
#63
Comments
Microsoft.Extensions.DependencyInjection
Microsoft.Extensions.DependencyInjection
think about the following project structure, where all projects have
The generated method(s) would need to register all generated types from
Ideally in a way, that does not need knowledge within Problem here: That said, the expected order of invocations would be:
If that´s true, we could choose to scan all direct and indirect references of Just wondering how we could determine when to actually emit such an extension-method - which assembly sits "on top" enough to actually benefit from such method and needs to actually register dependencies? Is it OK to jsut emit variants on all projects? Oh, and it should not degrade build-times in a noticable way^^ |
Most simple solution would probably be to generate said extension-method for all of the above assemblies, which (directly or indirectly) reference In above sample solution, that would be in the following namespaces:
or the other way around:
(With or without the Such an approach would also work when auto-registrations would need to be generetaed for other containers... |
Microsoft.Extensions.DependencyInjection
Microsoft.Extensions.DependencyInjection
An alternative approach could be to let the namespace Microsoft.Extensions.DependencyInjection.TypealizR.Library.A;
public static TypealizRExtensions{
public static IServiceCollection AddTypealizR(this IServiceCollection services) {
services.AddScoped(x => x.GetRequiredService<IStringLocalizer<ResourcesFromA>>().Typealize());
return services;
}
} namespace Microsoft.Extensions.DependencyInjection.TypealizR.Library.B;
public static TypealizRExtensions{
public static IServiceCollection AddTypealizR(this IServiceCollection services) {
services.AddScoped(x => x.GetRequiredService<IStringLocalizer<ResourcesFromB>>().Typealize());
return services;
}
} namespace Microsoft.Extensions.DependencyInjection.TypealizR.Library.C;
public static TypealizRExtensions {
public static IServiceCollection AddTypealizR(this IServiceCollection services) {
services.AddScoped(x => x.GetRequiredService<IStringLocalizer<ResourcesFromC>>().Typealize());
Microsoft.Extensions.DependencyInjection.TypealizR.Library.B.TypealizRExtensions.AddTypealizR(services);
return services;
}
} namespace Microsoft.Extensions.DependencyInjection.TypealizR.Library.D;
public static TypealizRExtensions {
public static IServiceCollection AddTypealizR(this IServiceCollection services) {
services.AddScoped(x => x.GetRequiredService<IStringLocalizer<ResourcesFromD>>().Typealize());
return services;
}
} namespace Microsoft.Extensions.DependencyInjection.TypealizR.Library.E;
public static TypealizRExtensions {
public static IServiceCollection AddTypealizR(this IServiceCollection services) {
services.AddScoped(x => x.GetRequiredService<IStringLocalizer<ResourcesFromE>>().Typealize());
Microsoft.Extensions.DependencyInjection.TypealizR.Library.D.TypealizRExtensions.AddTypealizR(services);
return services;
}
} namespace Microsoft.Extensions.DependencyInjection.TypealizR.App;
public static TypealizRExtensions {
public static IServiceCollection AddTypealizR(this IServiceCollection services) {
services.AddScoped(x => x.GetRequiredService<IStringLocalizer<ResourcesFromApp>>().Typealize());
Microsoft.Extensions.DependencyInjection.TypealizR.Library.A.TypealizRExtensions.AddTypealizR(services);
Microsoft.Extensions.DependencyInjection.TypealizR.Library.B.TypealizRExtensions.AddTypealizR(services);
Microsoft.Extensions.DependencyInjection.TypealizR.Library.C.TypealizRExtensions.AddTypealizR(services);
//Microsoft.Extensions.DependencyInjection.TypealizR.Library.D.TypealizRExtensions.AddTypealizR(services);
Microsoft.Extensions.DependencyInjection.TypealizR.Library.E.TypealizRExtensions.AddTypealizR(services);
return services;
}
} |
The
source-generator
should emit an extension-method for use withIServiceCollection
, which registers all types being generated, to reduce the amount of boilerplate-code necessary in order to utilize injection of typealized resources.The text was updated successfully, but these errors were encountered: