Closed scovel closed 2 years ago
There's been support added for this to Grace recently:
var builder = WebApplication.CreateBuilder(args);
builder.Host.UseServiceProviderFactory(new GraceServiceProviderFactory());
builder.Host.ConfigureContainer<DependencyInjectionContainer>(c => c.Configure(...));
var app = builder.Build();
@ipjohnson Perhaps this could be added to the documentation and/or the README on the front page?
Thanks for the quick response. Another reason I like Grace. Your support is excellent.
Is this in the Beta? I don't see it in 7.2.1, I'm not seeing it in 8.0.0-beta132.
builder.Host.UseServiceProviderFactory(new GraceServiceProviderFactory());
Program.cs(17, 44): [CS7036] There is no argument given that corresponds to the required formal parameter 'configuration' of 'GraceServiceProviderFactory.GraceServiceProviderFactory(IInjectionScopeConfiguration)'
Am I missing an import or something?
Thanks
Yep it should be in 8.0.0-beta132, but I haven't tried it out myself.
I may have messed up the syntax. Try this instead:
builder.Host.ConfigureContainer<DependencyInjectionContainer>((_, c) => c.Configure(...));
Also, if I'm not mistaken you can replace this:
builder.Host.UseServiceProviderFactory(new GraceServiceProviderFactory());
with this:
builder.Host.UseGrace();
Yes, I was doing .UseGrace, but needed to know how to get direct access to the container in the main() as opposed to the Startup.cs. It seems like your new syntax compiles. I need to throw a little more code together to make sure it's all working.
builder.Host.ConfigureContainer<DependencyInjectionContainer>((_, c) =>
{
c.Configure(block =>
{
// register all [Tracing] attributes for Interception
block.OwningScope.InterceptAttribute<TracingAttribute, TracingInterceptionHandler>();
});
});
Does this look correct?
@scovel did @silkfire suggestion work for you?
Yes, that did. Thanks for all your help.
Love you lib, been using it for years.
I'm trying to figure out how to use Grace with the new "minimal api" templates for .Net 6.0. I'd call it "Startup-less", since there is no magic Startup.cs class.
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis?view=aspnetcore-6.0
Specifically, in my old Startup.cs I had the following magic:
In the above article, to access the built-in DI container, you do the following:
How do you accomplish the same with Grace?
Thanks!