mrpmorris / Fluxor

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

How to register Fluxor properly with Blazor Server and .NET6? #266

Closed Rhywden closed 2 years ago

Rhywden commented 2 years ago

The documentation states that you should do this:

// Server-side
using Fluxor;

public void ConfigureServices(IServiceCollection services)
{
  ...

  // Add the following
  var currentAssembly = typeof(Startup).Assembly;
  services.AddFluxor(options => options.ScanAssemblies(currentAssembly));
}

However, with .NET6 the program.cs default page looks a bit different. There's no Startup anymore. Basically looks like this now:

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();

var app = builder.Build();

app.Run();

So, what am I supposed to use now for the assembly scan?

robertmrobo commented 2 years ago
using Fluxor;

builder.Services.AddFluxor(opt =>
{
    opt.ScanAssemblies(typeof(Program).Assembly); //This is what you are basically asking for
    opt.ScanAssemblies(typeof(GetAllAssociationsAction).Assembly); // one of the external assemblies I have on my app
    opt.ScanAssemblies(typeof(GetUserByAzureIdAction).Assembly); // another external assemblies I have on my app
    opt.UseRouting();
    opt.UseReduxDevTools();
});
Rhywden commented 2 years ago

I'm very much obliged, thank you very much!

robertmrobo commented 2 years ago

I'm very much obliged, thank you very much!

You are welcome.

Happy Fluxoring..! Happy Coding..! <3