-
Notifications
You must be signed in to change notification settings - Fork 3
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
AddPageModelActivation() can't resolve Microsoft-specified types like LogoutModel<IdentityUser> #9
Comments
Thank you for reporting this issue. This part of the ASP.NET Core stack is still something that might need improvement. Your issue is a bit tricky, because there are a few things going on. First of all, the resolved type is a generic type defined internally inside the Microsoft libraries. That's why it hasn't been registered by Simple Injector. It only registers concrete, non-generic types that are part of application parts of type The This is why the built-in behavior can resolve an We will have to figure out how to work with this scenario, without having to revert to weird hacks that prevent DI-container verification. A huge problem here is that the class in question is internal. This makes it very hard to register it by hand. For now, you can work around the issue by doing the following: public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddSimpleInjector(container, options =>
{
options.AddAspNetCore()
.AddControllerActivation()
.AddViewComponentActivation()
.AddPageModelActivation()
.AddTagHelperActivation();
});
services.AddSingleton<IPageModelActivatorProvider>(
new FixedPageModelActivatorProvider(
container,
new SimpleInjectorPageModelActivatorProvider(container)));
} Here, public class FixedPageModelActivatorProvider : IPageModelActivatorProvider
{
private readonly Container container;
private readonly IPageModelActivatorProvider decoratee;
public FixedPageModelActivatorProvider(Container container, IPageModelActivatorProvider decoratee)
{
this.container = container;
this.decoratee = decoratee;
}
public Func<PageContext, object> CreateActivator(CompiledPageActionDescriptor descriptor)
{
try
{
return this.decoratee.CreateActivator(descriptor);
}
catch (InvalidOperationException)
{
var producer = Lifestyle.Transient.CreateProducer(
serviceType: descriptor.ModelTypeInfo.AsType(),
implementationType: descriptor.ModelTypeInfo.AsType(),
container: this.container);
return _ => producer.GetInstance();
}
}
public Action<PageContext, object> CreateReleaser(CompiledPageActionDescriptor descriptor) =>
this.decoratee.CreateReleaser(descriptor);
} This should fix your problem for now, until we have a good fix for this problem. |
feature-728 branch created. |
Hi @oleg-gochachko, I'm currently trying to implement a fix for this issue. I, however, need to test my assumptions, but have little experience with PageModels myself. Would you be so kind to provide me with a small sample ASP.NET Core application that reproduces the issue? |
I postponed this feature until I have more information available. Feel free to provide me with information that helps me address this issue. |
I follow https://simpleinjector.org/aspnetcore guide to integrate SI to my web site (standard template with authentication).
However, when I try to open login page - I recieve the folloving error:
Stack trace:
After several hours of tries I'm able to start the project propery by using these configurations:
and
As you may see method
.AddPageModelActivation()
commented and obsolete methodRegisterPageModels(app);
andservices.AddSingleton<IPageModelActivatorProvider>
added.I think
AddPageModelActivation
not enumerate some of Identity view models and should be fixed.The text was updated successfully, but these errors were encountered: