Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc Autofac未正确处理对象_Asp.net Mvc_Memory Leaks_Autofac - Fatal编程技术网

Asp.net mvc Autofac未正确处理对象

Asp.net mvc Autofac未正确处理对象,asp.net-mvc,memory-leaks,autofac,Asp.net Mvc,Memory Leaks,Autofac,我确信我没有正确设置autofac。我的应用程序内存消耗在1.5gb左右,几乎没有任何用户。我完全不知道内存使用是从哪里来的。因此,我将发布几乎整个DI配置 public virtual void Register(ContainerBuilder builder) { //data layer var dataSettingsManager = new DataSettingsManager(); var dataProv

我确信我没有正确设置autofac。我的应用程序内存消耗在1.5gb左右,几乎没有任何用户。我完全不知道内存使用是从哪里来的。因此,我将发布几乎整个DI配置

        public virtual void Register(ContainerBuilder builder)
    {
        //data layer
        var dataSettingsManager = new DataSettingsManager();
        var dataProviderSettings = dataSettingsManager.LoadSettings();
        builder.Register(c => dataSettingsManager.LoadSettings()).As<DataSettings>();
        builder.Register(x => new EfDataProviderManager(x.Resolve<DataSettings>())).As<BaseDataProviderManager>().InstancePerDependency();
        builder.Register(x => (IEfDataProvider)x.Resolve<BaseDataProviderManager>().LoadDataProvider()).As<IEfDataProvider>().InstancePerDependency();

        if (dataProviderSettings != null && dataProviderSettings.IsValid())
        {
            var efDataProviderManager = new EfDataProviderManager(dataSettingsManager.LoadSettings());
            var dataProvider = (IEfDataProvider)efDataProviderManager.LoadDataProvider();
            dataProvider.InitConnectionFactory();

            builder.Register<IDbContext>(c => new CellObjectContext(dataProviderSettings.DataConnectionString)).InstancePerHttpRequest();
        }
        else
        {
            throw new Exception("ConnectionString in the web.config/app.config hasn't been defined");
        }

        builder.Register(c => (new HttpContextWrapper(HttpContext.Current) as HttpContextBase))
            .As<HttpContextBase>().InstancePerHttpRequest();


        //helpers
        builder.RegisterType<StoreOrderHelper>().As<IStoreOrderHelper>().InstancePerHttpRequest();
        builder.RegisterType<GiftCardHelper>().As<IGiftCardHelper>().InstancePerHttpRequest();
        builder.RegisterType<ProductHelper>().As<IProductHelper>().InstancePerHttpRequest();
        builder.RegisterType<ProspectHelper>().As<IProspectHelper>().InstancePerHttpRequest();
        builder.RegisterType<OfferProductHelper>().As<IOfferProductHelper>().InstancePerHttpRequest();
        builder.RegisterType<CustomerHelper>().As<ICustomerHelper>().InstancePerHttpRequest();
        builder.RegisterType<CartHelper>().As<ICartHelper>().InstancePerHttpRequest();

        //cache
        builder.RegisterType<MemcachedClient>().As<IMemcachedClient>().SingleInstance();
        builder.RegisterType<MemoryCacheManager>().As<ICacheManager>().Named<ICacheManager>("cache_static").SingleInstance();
        builder.RegisterType<MemcachedManager>().As<ICacheManager>().Named<ICacheManager>("cache_static_mem").InstancePerHttpRequest();
        builder.RegisterType<RequestCacheManager>().As<ICacheManager>().Named<ICacheManager>("cache_per_request").InstancePerHttpRequest();

        //repository
        builder.RegisterGeneric(typeof(EfRepository<>)).As(typeof(IRepository<>)).InstancePerHttpRequest();

        //services
        builder.RegisterType<SettingService>().As<ISettingService>()
            .InstancePerHttpRequest();
        builder.RegisterType<ContentService>().As<IContentService>().InstancePerHttpRequest();
        builder.RegisterType<StoreOrderService>().As<IStoreOrderService>()
            .WithParameter(ResolvedParameter.ForNamed<ICacheManager>("cache_per_request"))
            .InstancePerHttpRequest();
        builder.RegisterType<OfferProductService>().As<IOfferProductService>()
            .InstancePerHttpRequest();
        builder.RegisterType<OfferProductService>().As<IOfferProductService>()
         .InstancePerHttpRequest().PropertiesAutowired(PropertyWiringFlags.AllowCircularDependencies);
        builder.RegisterType<ProductService>().As<IProductService>()
            .InstancePerHttpRequest();
        builder.RegisterType<SubstituteService>().As<ISubstituteService>().InstancePerHttpRequest();

        builder.RegisterType<ErrorService>().As<IErrorService>()
            .InstancePerHttpRequest();

       builder.RegisterType<BonusService>().As<IBonusService>().InstancePerHttpRequest()
           .InstancePerHttpRequest();

        builder.RegisterType<TastingNoteService>().As<ITastingNoteService>().InstancePerHttpRequest()
            .InstancePerHttpRequest();

        builder.RegisterType<OfferProductAdminService>().As<IOfferProductAdminService>().InstancePerHttpRequest();
        builder.RegisterType<ResourceService>().As<IResourceService>().InstancePerHttpRequest();
        builder.RegisterType<FeedProductService>().As<IFeedProductService>().InstancePerHttpRequest();
        builder.RegisterType<ClubService>().As<IClubService>().InstancePerHttpRequest();

        builder.RegisterType<CasePricingService>().As<ICasePricingService>().InstancePerHttpRequest()
            .InstancePerHttpRequest();

        builder.RegisterType<StoreDiscountService>().As<IStoreDiscountService>().InstancePerHttpRequest()
            .InstancePerHttpRequest();

        builder.RegisterType<MixComponentService>().As<IMixComponentService>().InstancePerHttpRequest();
        builder.RegisterType<BrandService>().As<IBrandService>().InstancePerHttpRequest();

        builder.RegisterType<CardTypeService>().As<ICardTypeService>()
            .InstancePerHttpRequest();


        builder.RegisterType<CategoryService>().As<ICategoryService>()
            .InstancePerHttpRequest();

        builder.RegisterType<ExcludedOfferProductService>().As<IExcludedOfferProductService>()
            .InstancePerHttpRequest();            

        builder.RegisterType<CustomerTitleService>().As<ICustomerTitleService>().InstancePerHttpRequest();
        builder.RegisterType<DeliveryInstructionsOptionService>().As<IDeliveryInstructionsOptionService>().InstancePerHttpRequest();        

        builder.RegisterType<SuburbService>().As<ISuburbService>().InstancePerHttpRequest();
        builder.RegisterType<PayPalOrderService>().As<IPayPalOrderService>().InstancePerHttpRequest();
        builder.RegisterType<ProspectInterface>().As<IProspectInterface>().InstancePerHttpRequest(); ;

        builder.RegisterType<CreditCardInterface>().As<ICreditCardInterface>().InstancePerHttpRequest();
        builder.RegisterType<CreditCardHelper>().As<ICreditCardHelper>().InstancePerHttpRequest();

        builder.RegisterType<GiftRecipientInterface>().As<IGiftRecipientInterface>().InstancePerHttpRequest();
        builder.RegisterType<GiftRecipientHelper>().As<IGiftRecipientHelper>().InstancePerHttpRequest();

        //register controllers

    }

我在Application_BeginRequest或Application_EndRequest中没有代码,也没有服务/存储库/助手实现IDisposable。此配置是否有任何问题???

从容器配置中,现在可以知道导致内存泄漏的原因。您应该使用内存探查器来查看导致内存泄漏的原因,如果是它的Autofac,那么您需要发布在内存泄漏中调用的相关类。您可能还需要发布更多关于在何处解决问题的信息。曾经手动解决过任何问题吗?哪里它是什么样的应用程序?(从上一部分猜测MVC,但最好也包括更多相关信息。)
var builder = new ContainerBuilder();

        DependencyRegistrar dr = new DependencyRegistrar();
        dr.Register(builder);
        builder.RegisterControllers(AppDomain.CurrentDomain.GetAssemblies());

        IContainer c = builder.Build();
        DependencyResolver.SetResolver(new AutofacDependencyResolver(c));
        _containerProvider = new ContainerProvider(c);