Skip to content
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

AddMediator(config => ..) not working #112

Open
dschreib42 opened this issue Sep 22, 2023 · 4 comments
Open

AddMediator(config => ..) not working #112

dschreib42 opened this issue Sep 22, 2023 · 4 comments

Comments

@dschreib42
Copy link

dschreib42 commented Sep 22, 2023

The namespace and scope configuration is not respected in v.2.1.7, but in version v2.0.30 it's working fine...

 var builder = WebApplication.CreateBuilder(...);

 builder.Services.AddMediator(config =>
 {
     config.Namespace = "Foo.Generated";
     config.ServiceLifetime = ServiceLifetime.Scoped;
 });
@martinothamar
Copy link
Owner

Hi!
I just checked out the 2.1 branch, and ran this code

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddMediator(
    options =>
    {
        options.Namespace = "SomeNs";
        options.ServiceLifetime = ServiceLifetime.Transient;
    }
);

builder.Services.AddControllers();

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

var mediator = app.Services.GetRequiredService<SomeNs.Mediator>();

based on the ASP.NET Core sample in this repo. This worked fine, the generated mediator ends up in SomeNs and the lifetime is transient. I'll need more information to help you debug, for example what environment you have, .NET version etc..

@dschreib42
Copy link
Author

dschreib42 commented Sep 26, 2023

I was using .NETt v6.0 with AutoFac on Windows 11

@martinothamar
Copy link
Owner

I added a sample for this using Autofac and .NET 6, seemed to work find here, unless I'm missing something..

image

466dbd7

@davidivkovic
Copy link

davidivkovic commented Dec 26, 2023

Same issue. Cannot post repro but the abstractions and generator are installed in separate projects. I am not using autofac.

builder.Services.AddMediator(options =>
{
    options.Namespace = "Properties.API.Mediator";
    options.ServiceLifetime = ServiceLifetime.Scoped;
});

produces:

" Invalid configuration detected for Mediator. Generated code for 'Singleton' lifetime, but got 'Scoped' lifetime from options. "

Meanwhile using

[assembly: MediatorOptions(Namespace = "Properties.API.Mediator", ServiceLifetime = ServiceLifetime.Scoped)]

works properly

Mediator.SourceGenerator 2.1.7
.NET SDK 8.0.100

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

3 participants