Skip to content

CodeGeneration not accessible from IWebHostBuilder #5

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

Open
zachsaw-lmg opened this issue Feb 22, 2024 · 1 comment
Open

CodeGeneration not accessible from IWebHostBuilder #5

zachsaw-lmg opened this issue Feb 22, 2024 · 1 comment

Comments

@zachsaw-lmg
Copy link

zachsaw-lmg commented Feb 22, 2024

Currently this command expects an IHostBuilder to be passed in for it to build a webhost. However, in integration tests, we typically spin up a webapp via WebApplicationFactory (fixture) to verify the codegen the devs committed in the repo is current and correct.

We do the following currently.

    private void GenerateCode(IServiceProvider services) =>
        new DynamicCodeBuilder(services, services.GetServices<ICodeFileCollection>().ToArray())
            {
                ServiceVariableSource = services.GetService<IServiceVariableSource>()
            }
            .WriteGeneratedCode(file =>
            {
                _fixture.TestOutputHelper?.WriteLine("Wrote generated code file to " + file);
            });

However, this is reaching into undocumented (read: no official doc means potentially unsupported) territory. Would be nice if there's an extension method in a nuget package for this method (and other useful ones in the oakton package) that doesn't require us to use undocumented interfaces.

@jeremydmiller
Copy link
Member

@zachsaw-lmg Just saw this today, sorry for the delay. I think I might ask for a PR for this one, but it shouldn't be that bad to do

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