ipjohnson / Grace.DependencyInjection.Extensions

Grace Extensions for ASP.Net Core
19 stars 7 forks source link

How to call WhatDoIHave from ASP.NET Core context? #10

Closed silkfire closed 5 years ago

silkfire commented 5 years ago

At the moment there doesn't seem to be a way to run WhatDoIHave() when running in an ASP.NET Core application.

I know that the service provider is in IApplicationBuilder.ApplicationService, but Grace.DependencyInjection.Extensions.GraceRegistration.GraceServiceProvider is a private class and its IInjectionScope is private too, so there's no way of running the extension method as of right now.

How do I access the container?

ipjohnson commented 5 years ago

Sounds like you are looking to call this in Startup.cs. One thing to note is that by default asp.net core registers hundreds of dependencies on it's own so this will be very large.

 var description =
                app.ApplicationServices.GetService<IExportLocatorScope>().WhatDoIHave();
silkfire commented 5 years ago

Now that's a very clever trick. Thank you!