Question

I am using NopCommerce_3.10. I am trying to make plugin with this tutorial : Plugin with data access

When i reached at Dependency Injection step i got error on InstancePerHttpRequest() method. i have added all references those are mentioned in this tutorial.but still i am getting error at this method.

LookDependencyRegistrar Class :

public class LookDependencyRegistrar : IDependencyRegistrar
    {
        private const string CONTEXT_NAME = "nop_object_context_product_look";

        public void Register(ContainerBuilder builder, ITypeFinder typeFinder)
        {
            //Load custom data settings
            var dataSettingsManager = new DataSettingsManager();
            DataSettings dataSettings = dataSettingsManager.LoadSettings();

            //Register custom object context
            builder.Register<IDbContext>(c => RegisterIDbContext(c, dataSettings)).Named<IDbContext>(CONTEXT_NAME).InstancePerHttpRequest();
            builder.Register(c => RegisterIDbContext(c, dataSettings)).InstancePerHttpRequest();

            //Register services
            builder.RegisterType<LookService>().As<ILookService>();

            //Override the repository injection
            builder.RegisterType<EfRepository<Look>>().As<IRepository<Look>>().WithParameter(ResolvedParameter.ForNamed<IDbContext>(CONTEXT_NAME)).InstancePerHttpRequest();
        }

        public int Order
        {
            get { return 0; }
        }

        /// <summary>
        /// Registers the I db context.
        /// </summary>
        /// <param name="componentContext">The component context.</param>
        /// <param name="dataSettings">The data settings.</param>
        /// <returns></returns>
        private LookObjectContext RegisterIDbContext(IComponentContext componentContext, DataSettings dataSettings)
        {
            string dataConnectionStrings;

            if (dataSettings != null && dataSettings.IsValid())
            {
                dataConnectionStrings = dataSettings.DataConnectionString;
            }
            else
            {
                dataConnectionStrings = componentContext.Resolve<DataSettings>().DataConnectionString;
            }

            return new LookObjectContext(dataConnectionStrings);
        }
    }

Error Message at InstancePerHttpRequest() method :

enter image description here

how can i resolve error at InstancePerHttpRequest() method?

Was it helpful?

Solution

InstancePerHttpRequest is an extension method residing in another namespace / assembly. You should import the following namespace for proper compilation:

using Autofac.Integration.Mvc;

OTHER TIPS

try to replace this line :

builder.RegisterType<LookService>().As<ILookService>();

replace it with

builder.RegisterType<LookService>().As<ILookService>().InstancePerHttpRequest();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top