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

CS0118: 'Mediator' is a namespace but is used like a type #65

Open
Houzhendong opened this issue Dec 13, 2022 · 4 comments
Open

CS0118: 'Mediator' is a namespace but is used like a type #65

Houzhendong opened this issue Dec 13, 2022 · 4 comments
Labels
bug Something isn't working
Milestone

Comments

@Houzhendong
Copy link

Houzhendong commented Dec 13, 2022

for better performance, i chose Mediator instead of IMediator, but i get CS0118: 'Mediator' is a namespace but is used like a type error, so i have to explicitly declare Mediator by "MyNameSpace.Mediator" for every call , do you have better way to solve this ?

example

using Microsoft.Extensions.DependencyInjection;

namespace ConsoleApp1
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var service = new ServiceCollection()
                .AddMediator(options => options.Namespace = "MyNamespace")
                .BuildServiceProvider();
        }
    }

    public class Test
    {
        private readonly IServiceProvider _service;

        public Test(IServiceProvider service)
        {
            _service = service;
        }

        public void ResolveMediator()
        {
            Mediator mediator = _service.GetRequiredService<Mediator>(); // here i will get cs0018 error
            MyNamespace.Mediator mediator1 = _service.GetRequiredService<MyNamespace.Mediator>(); // this will work, but i wanna know is there any better way to avoid type "MyNamespace." every time 
        }
    }
}
@gabrielacos
Copy link

Can add an "s" at the end of your namespace. It may be confusing it with Mediator packages.

@martinothamar
Copy link
Owner

Ahh, no matter what namespace is configured, the Mediator implementation will always collide with the Mediator namespace from the abstractions package (where IRequest etc is). One option is to create a global alias using global usings: global using MyMediator = MyNamespace.Mediator or similar. I'll have to think about refactoring this without having too many breaking changes... Thanks for bringit it up 👍

@Meryovi
Copy link

Meryovi commented Mar 1, 2023

I have stumbled upon this one. You can also use Mediator.Mediator instead of just Mediator and it will work properly.

@martinothamar martinothamar added the bug Something isn't working label Jun 21, 2023
@martinothamar martinothamar added this to the 3.0 milestone Jun 21, 2023
@TimothyMakkison
Copy link
Contributor

TimothyMakkison commented Jun 25, 2023

I keep getting a MSBuildLocator error. In the past I've fixed similar issues by installing NuGet.Frameworks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants