RazorLightDependencyBuilder ExcludeAssemblies
So this builder is basically broken. When adding ExcludedAssemblies via method ExcludeAssemblies() the DefaultMetadataReferenceManager will not receive those elements, because it was added to services (via services.TryAddSingleton<IMetadataReferenceManager, DefaultMetadataReferenceManager>();) before finishing setting the RazorLightOptions. The constructor in DefaultMetadataReferenceManager with IOptions<RazorLightOptions> will receive outdated data (empty list in it). So my suggestion is to remove AddRazorLight(this IServiceCollection services) and replace this with AddRazorLight(this IServiceCollection services, Action<RazorLightOptions> opts); This way we will be able to init all options before registering all other services.
Can you please provide a sample of what is wrong. I dont really look at my configuration stuff very often so a repro is super time saving. For context, in the past, I would guess what the heck people were doing and it would take hours or days to reproduce, until I found a blog post on the Internet and realized everyone was copying some dude's shitty code.
@mikart143 Just following up on this.
If I understand your point, it's that the following 3 methods are not composable:
https://github.com/toddams/RazorLight/blob/master/src/RazorLight/RazorLightDependencyBuilder.cs#L65-L94
And that you think we should address it by creating
public RazorLightDependencyBuilder AddRazorLight(this IServiceCollection services, Action<RazorLightOptions> opts)
{
_services.Configure<RazorLightOptions>(opts);
return this;
}
Or perhaps we should be using named options instead: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/options?view=aspnetcore-6.0#named-options-support-using-iconfigurenamedoptions