Skip to content

Commit

Permalink
Merge pull request #49 from fingers10/master
Browse files Browse the repository at this point in the history
Update README.md with example for reading host environment
  • Loading branch information
jsakamoto authored Dec 8, 2024
2 parents df86c75 + 2e8126c commit c61d627
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ This is important for your Blazor WebAssembly components to work fine in the pre

The `ConfigureServices(...)` static local function can also have an `IConfiguration` argument that reflects the contents of the `wwwroot/appsetting.json` JSON file.

The prerendering package supposes that the `ConfigureServices` method has no or only one `string` argument and that the string argument means the app's base address if there is one. The package doesn't suppose that the `ConfigureServices` method has two or more string parameters and can't determine those argument names. (The argument names of methods are usually minified at the publishing time.)

If you need to pass the environment name to the `ConfigureServices`, please pass the `IWebAssemblyHostEnvironment` to its argument like this.

```cs
// Program.cs
...
ConfigureServices(builder.Services, builder.HostEnvironment, builder.Configuration);
...
static void ConfigureServices(IServiceCollection services, IWebAssemblyHostEnvironment webHostEnv, IConfiguration configuration)
{
// You can get the environment name via "webHostEnv.Environment".
// You can also get the app base address via "webHostEnv.BaseAddress".
...
```

### Root component type and selector

In some cases, suppose the type and selector of the root component of your Blazor WebAssembly app are not `{RootNamespace}.App` and `#app` or `app`.
Expand Down

0 comments on commit c61d627

Please sign in to comment.