问题
I've been looking at using CQS pattern with EF Core within an asp.net Core web application.
I found this sample, which seems to be what I want however the DI container used is Ninject.
I can't seem to be able to translate the Ninject configuration into the inbuilt DI container in asp.net core.
Specifically my problem is with these lines:
Bind<IQueryFactory>().ToMethod(t => new QueryFactory(x => Container.Current.Resolve(x))).InTransientScope();
Bind<ICommandsFactory>()
.ToMethod(t => new CommandFactory(x => (object[]) Container.Current.ResolveAll(x)))
.InTransientScope();
I have gotten this far:
services.AddTransient<IQueryFactory>(qf => new QueryFactory(q => q));
But I'm not sure how to actually do this part in asp.net core di container:
Container.Current.Resolve(x)
回答1:
It would seem I was overthinking it and I have resolved my problem.
services.AddTransient<IQueryFactory>
(serviceProvider => new QueryFactory(serviceProvider.GetService));
来源:https://stackoverflow.com/questions/56260643/what-is-the-equivalent-code-for-the-asp-net-core-di-framework-from-this-example