Skip to content
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

RazorLightDependencyBuilder ExcludeAssemblies #476

Open
mikart143 opened this issue Mar 30, 2022 · 2 comments
Open

RazorLightDependencyBuilder ExcludeAssemblies #476

mikart143 opened this issue Mar 30, 2022 · 2 comments

Comments

@mikart143
Copy link

mikart143 commented Mar 30, 2022

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 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.

@jzabroski
Copy link
Collaborator

jzabroski commented Mar 30, 2022

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.

@jzabroski
Copy link
Collaborator

@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

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

No branches or pull requests

2 participants