-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@inject support in .NET Core MVC views #990
Comments
The discussion that you mentioned last actually contains code that, according to the OP, works. |
Thank you! That's what I wanted to confirm. I just curios why it is not part of SimpleInjector default integration with .NET Core MVC? |
Mainly because of two reasons:
I hope this makes sense. |
Good points, especially #2. I'm about to migrate large application to .NET Core. It has clever framework on top of MVC with again clever code in MVC views. And I agree it would be better not to have it and keep views as simple as possible. Thank you, again for great DI library! |
@dotnetjunkie thank you again for pointing to right direction. Code from this response works as intended and I was able to inject dependencies using [Import] attribute. It is nice to be able to do it as I have couple of properties in our base razor page class where we use service locator pattern and now we can use proper DI. simpleinjector/SimpleInjector.Integration.AspNetCore#25 (comment) But my question was not clear and in fact I was looking to way to inject dependency using @Inject directive.
It still fails with error:
In generated Index.cshtml.cs file property I'm trying to inject RazorInject attribute
|
From the stack trace I understand that your custom |
I guess we have to call Microsoft.AspNetCore.Mvc.Razor.RazorPagePropertyActivator from SimpleInjectorRazorpageActivator. Comment in SimpleInjectorRazorpageActivator says:
As far as I can see RazorPagePropertyActivator uses build-in service provider and not extendable,
|
I think I'm starting to see the problem here. The implementation I proposed in 25, calls into the core behavior and let Simple Injector inject properties that are marked with the Since the core behavior isn't extendable, the only option is to skip calling into the core behavior. But that causes new problems, because there is a set of dependencies that seem to be injected through a different mechanism. Not initializing them might cause issues of its own. It might be possible to work around these issues, but at this point I'm unsure how to proceed. |
I don't have that many services used @Inject. So in my case I think reasonable workaround would be to register services used with @Inject in MS DI container and resolve them through SimpleInjector.
|
Hi,
I think this question was already asked before but reading through several threads I still don't have clear understanding if @Inject can be used with SimpleInjector. Clearly it does not work by default but is there any workaround?
For the record I went through these.
#860
#362
simpleinjector/SimpleInjector.Integration.AspNetCore#25
Thank you
The text was updated successfully, but these errors were encountered: