0

I have my custom service collection

    public static IServiceProvider Init()
    {
        var serviceProvider = new ServiceCollection()
            .ConfigureDatabase()
            .ConfigureCsvExporter()
            .ConfigureServices()
            .BuildServiceProvider();

        ServiceProvider = serviceProvider;
        
        return serviceProvider;
    }

and I want to add controllers to webserver

var server = new WebServer(o => o
                .WithUrlPrefix(url)
                .WithMode(HttpListenerMode.EmbedIO))
            .WithCors()
            .WithLocalSessionManager()
            .WithWebApi("/api", m => m.WithController<TestController>()
                .WithController<SettingsController>()
                .WithController<ReportController>()
                .WithController<SystemController>())
            .WithModule(new ActionModule("/", HttpVerbs.Any, ctx => ctx.SendDataAsync(new { Message = "Error" })));

But I want to resolve services from my custom container in controller constructor
Is there any solution how to resolve webserver controller with my custom container objects?
Like when I have this code in .ConfigureCsvExporter()

services.AddSingleton<ICsvExporter, CsvExporter>();

how to resolve it in Controller like:

public TestController(ICsvExporter exp)
{
    ...
}
Qhori
  • 157
  • 12
  • I can't understand your demand clearly, had you check the official about the [dependency injection](https://learn.microsoft.com/en-us/xamarin/xamarin-forms/enterprise-application-patterns/dependency-injection)? – Liyun Zhang - MSFT Mar 31 '22 at 03:55
  • I understand DI, but I want to somehow use my custom container with embedio webserver... via some decorator or stuff. Maybe the call of WithController with factory should do the trick... but that is not what I want – Qhori Mar 31 '22 at 07:18
  • Can this [case](https://stackoverflow.com/questions/51166734/using-xamarin-forms-with-iserviceprovider) which uses the Splat provide you some help? – Liyun Zhang - MSFT Mar 31 '22 at 10:08

0 Answers0