GithubHelp home page GithubHelp logo

Comments (9)

tillr avatar tillr commented on July 27, 2024 1

Sounds good!

from piral.blazor.

FlorianRappl avatar FlorianRappl commented on July 27, 2024

Where should the appsettings.json live? Should it be in the app shell or in pilets?

My proposal is to support the IConfiguration via app shell configuration. Now in your app shell you can hand over something to the initialization of piral-blazor, which determines the key / values. It's then up to you to either read some JSON or gather the configuration from different sources. Would that work?

from piral.blazor.

tillr avatar tillr commented on July 27, 2024

While it probably isn't the most intuitive way for Blazor WASM developers, who are used to employ appsettings*.json files for that purpose, I can think of various use cases which may require the provision of pilet configuration via the app shell anyway. So yes, your proposed way is fine.

from piral.blazor.

FlorianRappl avatar FlorianRappl commented on July 27, 2024

Well, I mean what is "intuitive". If you work in a distributed environment then suddenly such old habits are required to change, so I'd argue not everything that was once established still makes sense in this new context.

The big issue with a local appsettings.json file is that a pilet should be environment independent. As such you just uploaded one static file - i.e., it won't change. Now if you do that the whole point of the appsettings.json is rendered useless, as you usually would want to change / adopt it to the target environment. However, there is already such a mechanism in the standard feed service; its configuration. It can be made per pilet per environment and it is gathered by the app shell. Additionally, the app shell can anyway be environment dependent, making the usual appsettings.json rather an app shell construct than a pilet construct.

Now with the given proposal I think whatever the user wants to go for works. It would even work having an appsettings.json per pilet, which is then consumed by the app shell and distributed to the pilets accordingly. But the important part is that IConfiguration would work.

from piral.blazor.

tillr avatar tillr commented on July 27, 2024

That's fine, go for it. I am not sure if I can follow you on this though:

However, there is already such a mechanism in the standard feed service; its configuration. It can be made per pilet per environment and it is gathered by the app shell.

In a Piral.Blazor pilet, how would I access that configuration where I need it (in Module.cs)? That bit seems to be missing at the moment. So either way you choose in your implementation, there should be a way to get that configuration into IConfiguration and use it when setting up DI.

from piral.blazor.

FlorianRappl avatar FlorianRappl commented on July 27, 2024

In a Piral.Blazor pilet, how would I access that configuration where I need it (in Module.cs)?

You access it via the IConfiguration instance. The thing is that the app shell would deliver any kind of global config and put it in the initial config passed to createBlazorApi, i.e., when setting up Piral.Blazor. With this information (and the local one provided to the pilet directly) the IConfiguration would be populated appropriately, consisting of global (i.e., available to all Blazor pilets) and local (i.e., only available to the current Blazor pilet) infos.

from piral.blazor.

FlorianRappl avatar FlorianRappl commented on July 27, 2024

Alright this is working, e.g.,

public class Module
{
    public static void ConfigureServices(IServiceCollection services, IConfiguration configuration)
    {
        Console.WriteLine("Received configuration is: {0} - {1}", configuration.GetValue<string>("foo"), configuration.GetValue<int>("someThingElse:c"));

        services.AddScoped<ExampleJsInterop>();
    }
}

Note that the second argument (of type IConfiguration) is optional. You can just omit it (as beforehand) and it would still work.

from piral.blazor.

prepfarm avatar prepfarm commented on July 27, 2024

Hi @FlorianRappl, I'm unable to get anything from appsettings inside of the Blazor Pilet. I tried moving around appsettings from wwwroot to root of the project, specifying Config in .csproj, setting copy to output folder, etc. but IConfiguration is always empty. Any help? Also not sure how to define (global) settings that will come to pilet from app shell? I don't see option for that when adding createBlazorApi

from piral.blazor.

FlorianRappl avatar FlorianRappl commented on July 27, 2024

This is all fully documented @prepfarm, see: https://github.com/smapiot/Piral.Blazor#overwriting-the-debug-meta-data

As the configuration is distributed the IConfiguration is drawn from the given options to the pilet. For local debugging you can (as documented) use the meta.json file.

Hope that helps!

from piral.blazor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.