autofac not resolving inherited class

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
6 years ago
Maybe a question for the autofac forum however i'll try here first.

I'm subclassing Nop.Web.Factories.CustomerModelFactory so that i can put some additional items on the customer navigation (my account). My class simply overrides one method however the class is never resolved by autofac.


Class definition is something like this...


public partial class MyCustomerModelFactory : CustomerModelFactory
    {
        // removed the ctor to keep this short

        public override CustomerNavigationModel PrepareCustomerNavigationModel(int selectedTabId = 0)
        {
            var model = base.PrepareCustomerNavigationModel(selectedTabId);
            model.CustomerNavigationItems.Add(new CustomerNavigationItemModel()
            {
                RouteName = "MyAccountItem",
                Title = "My Account Item",
                Tab = CustomerNavigationEnum.Info,
                ItemClass = "customer-info"
            });
            return model;
        }

    }



Registration (in my plugin) is something like this...


builder.RegisterType<MyCustomerModelFactory>()
       .As<ICustomerModelFactory>()
       .PreserveExistingDefaults()
       .InstancePerLifetimeScope();



Pretty much as you'd expect.


I've tried this several ways.

Plan A: In my plugin
Plan B: In a separate class file in nop.web

I've tried changing the registration order. No joy.
Using .PreserveExistingDefaults() made no difference.

The only way i got my class to resolve was to comment out the registration for CustomerModelFactory but I'd rather not do that.

Ideas?
6 years ago
Just a guess... You might try
   .As<CustomerModelFactory>()

(the class, not the interface)
6 years ago
New York wrote:
Just a guess... You might try
   .As<CustomerModelFactory>()

(the class, not the interface)



Hi and thanks for the response. Only problem is nop is declaring ICustomerModelFactory in various places as ctor params. So I'd have to hunt through and change those and again, I want to avoid changing the core if possible - or as little as possible.

Still i find it odd that the child class is not resolved despite what the (autofac) docs say. I'm wondering if its an autofac issue.
6 years ago
FYI

removing .PreserveExistingDefaults() and setting the Order to higher number than the default registration has worked. Thought I tried that but i must have kept the PreserveExistingDefaults() call in place.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.