mrpmorris / Fluxor

Fluxor is a zero boilerplate Flux/Redux library for Microsoft .NET and Blazor.
MIT License
1.27k stars 147 forks source link

Is there a Programmatic Alternative to <Fluxor.Blazor.Web.StoreInitializer /> in App.razor? #363

Closed RodDaSilvaWCO closed 1 year ago

RodDaSilvaWCO commented 1 year ago

Hi,

I have plans to work heavily with Fluzor in Blazor but I have hit a snag. All my Blazor components are in the form of dynamically loaded standalone RCL (Razor Component Libraries) that get loaded into an existing Blazor framework (see Oqtane here on GitHub).

The issue in a nutshell is I don't have access to the framework's App.razor file. So I can't add the requisite to it to initialize the store. By the time my RCL is loaded dynamically by the Oqtane framework the Blazor app is already up and running.

Oqtane's framework supports calling into the RCL Modules's IServerStartup class providing the IServiceCollection so I am able to provide the dependecies that my module requires - in this case Fluzor:

// Oqtane framework automatically calls the ConfigureServices() method for all classes implementing IServerStartup **public class ServerStartup : IServerStartup
{ public void ConfigureServices(IServiceCollection services) {

region Enable Fluzor

        foreach (var a in AppDomain.CurrentDomain.GetAssemblies())
        {
            if (a.GetName().FullName.Contains("MyModules"))
            {
                services.AddFluxor(options => options.ScanAssemblies(a));
            }
        }
        #endregion
    }

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {}

    public void ConfigureMvc(IMvcBuilder mvcBuilder) {}
}**

The issue occurs when my Blazor razor component Oqtane Module attempts to render:

There is no registered service of type 'Fluxor.IState`1[MyFluxorModuleState]'.

How can I perform the equivalent of what does for me in the App.razor, programmatically at the time of dependency injection in the routine above?

Thanks, Rod