Autofac Nhibernate内存泄漏

时间:2017-10-31 21:55:10

标签: memory-leaks fluent-nhibernate autofac

我们有使用autofac和FluentNhibernate的WCF服务。问题是它导致内存泄漏。每2-3小时后,我们的应用程序变得非常慢,我们必须重新启动应用程序池。

以下是我们的Global.asax文件中用于Autofac注册组件的Application_start中的代码

我该怎么做才能解决这个问题?或者从哪里开始寻找?

var builder = new ContainerBuilder();

builder.RegisterAssemblyTypes(typeof(IPwoSummaryCategoryService).Assembly).AsImplementedInterfaces();

builder.RegisterType<TemplateServiceCollection>().As<ITemplateServiceCollection>();

// Register Singletons
builder.RegisterType<QueryFacade>().As<IQueryFacade>().SingleInstance();
builder.RegisterType<CommandAggregator>().As<ICommandAggregator>().SingleInstance();

// Register open generics    builder.RegisterAssemblyTypes(typeof(ICommandHandler<>).Assembly).AsClosedTypesOf(typeof(ICommandHandler<>));
builder.RegisterInstance<MessageBrokerClient>(new MessageBrokerClient(Activator.CreateInstance<CustomMessageFormatter>(), AppConfiguration.MSMQRequestQueueUri, AppConfiguration.MSMQUser, false))
    .As<IMessageBrokerClient>().SingleInstance();
builder.RegisterInstance<Logger>(new Logger(HostingEnvironment.ApplicationPhysicalPath)).As<ILogger>();
builder.RegisterType<QuotesUnlockedByAdmin>().As<IQuotesUnlockedByAdmin>().SingleInstance();

// Register the Seed Data Builder
builder.RegisterType<SeedDataBuilder>();

// Register WCF Web Services
builder.RegisterType<QueryService>();
builder.RegisterType<CommandService>();
builder.RegisterType<MasterDataService>();
builder.RegisterType<AuthenticationService>();
builder.RegisterType<UserProfileService>();

//builder.RegisterType<OfflineSyncService>();
builder.RegisterType<ExternalDataQueryService>();
builder.RegisterType<DataContextProvider>().As<IDataContextProvider>().SingleInstance();

builder.RegisterAssemblyTypes(typeof(IDataContext).Assembly,typeof(DataContext).Assembly).AsImplementedInterfaces();

// Create a single Session Activator (manages multiple Session Factories) per AppDomain
builder.Register(context => SessionActivator.Build.FromConfiguration(new Configuration())).As<ISessionActivator>().SingleInstance();
builder.RegisterType<DataContextProxy>();

// Custom Registration for the CurrencyConverter
builder.Register(context => new CurrencyConverter(context.Resolve<IMasterQueryFacade>().GetCurrencies())).As<ICurrencyConverter>().SingleInstance();
var container = builder.Build();
AutofacHostFactory.Container = container;
ServiceLocator.SetLocatorProvider(() => new AutofacContrib.CommonServiceLocator.AutofacServiceLocator(container));

// Pre-populate the database with seed data (if missing)
container.Resolve<SeedDataBuilder>().InitializeSeedData();

0 个答案:

没有答案