ServiceProvider must have at least one public constructor to be plugged in by StructureMap

1k views Asked by At

I am trying to use an internal plugin (organisation specific) for some task implementation, in order to call the methods through plugin I need to pass the dependencies. I am done with the initial part but when I try to register in PreAppStart using:

config.For<IServiceProvider>().Use<ServiceProvider>()

I get below error:

    System.ArgumentOutOfRangeException
  HResult=0x80131502
  Message=Specified argument was out of the range of valid values.
Parameter name: Microsoft.Extensions.DependencyInjection.ServiceProvider must have at least one public constructor to be plugged in by StructureMap

My analysis: I have got to know that the ServiceProvider class is used for dot net core but my solution is in standard dot net (4.7) and I need to implement this plugin in order to complete the work.

Also I have tried this:

   config.For<IServiceProvider>().Use<ServiceProvider>().Ctor<string>("randomParam").Is("ranVal");

but still the error is same. Please help!

1

There are 1 answers

0
JonasH On

You are telling structure map that when something needs a IServiceProvider it should create a ServiceProvider object. And it tells you that it cannot since ServiceProvider does not have a public constructor.

You probably want to register an actual object to use. like this

 config.For<IServiceProvider>().UseInstance(myServiceProviderReference);

There is some methods to create a service provider, but this is part of .Net platform extensions. I'm unsure if this is available for .net framework projects.