(&amp quot的意思;\n客户端已断开\n&amp quot的意思;);start=clock();

诚问解数独的c语言思路及代码。_百度知道I've successfully implemented Session-per-HttpRequest using Autofac.
I'm unhappy with my implementation because I am going through DependencyResolver and not relying on parameters provided by AutoFac. If I rely on the ISession parameter provided by AutoFac, then I receive a warning with NHProf indicating that there are multiple Sessions in use. If I go through DependencyResolver, the warning from NHProf disappears, but the usage feels incorrect to me.
I have followed the Autofac + MVC4.0 guidelines outlined here:
I've also used this guide as a reference. It indicates that it should be possible to accept ISession as a constructor parameter:
Here's how I build my Autofac container:
public class AutofacRegistrations
public static void RegisterAndSetResolver()
var containerBuilder = new ContainerBuilder();
containerBuilder.RegisterControllers(Assembly.GetExecutingAssembly());
Only generate one SessionFactory ever because it is expensive.
containerBuilder.Register(x =& new NHibernateConfiguration().Configure().BuildSessionFactory()).SingleInstance();
Everything else wants an instance of Session per HTTP request, so indicate that:
containerBuilder.Register(x =& x.Resolve&ISessionFactory&().OpenSession()).As&ISession&().InstancePerHttpRequest();
containerBuilder.Register(x =& LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType)).As&ILog&().InstancePerHttpRequest();
containerBuilder.RegisterType&NHibernateDaoFactory&().As&IDaoFactory&().InstancePerHttpRequest();
containerBuilder.RegisterType&StreamusManagerFactory&().As&IManagerFactory&().InstancePerHttpRequest();
containerBuilder.RegisterModule adds all the required http modules to support per web request lifestyle and change default controller factory to the one that uses Autofac.
containerBuilder.RegisterModule(new AutofacWebTypesModule());
IContainer container = containerBuilder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
And here is my base controller class. Note the commented out code which original accepted session as a parameter:
public abstract class StreamusController : Controller
protected readonly ILog L
protected new readonly ISession S
protected StreamusController(ILog logger, /*ISession session*/)
if (logger == null) throw new ArgumentNullException("logger");
//if (session == null) throw new ArgumentNullException("session");
TODO: Is this different than passing ISession into Controller with AutoFac?
Session = DependencyResolver.Current.GetService&ISession&();
//Session =
I am experiencing different results with NHProf based on whether I work with ISession as a parameter or access it through DependencyResolver. Why? My understanding is that these two means should be EXACTLY THE SAME!
For reference, here's my Lazy NHibernateConfiguration/ISessionFactory implementation. I don't think it's exceedingly relevant to the issue at hand:
public class NHibernateConfiguration
public FluentConfiguration Configure()
string connectionString = ConfigurationManager.ConnectionStrings["default"].ConnectionS
FluentConfiguration fluentConfiguration = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008.ConnectionString(connectionString).ShowSql().FormatSql())
.Mappings(cfg =& cfg.FluentMappings.AddFromAssemblyOf&UserMapping&())
.ExposeConfiguration(ConfigureStreamusDataAccess);
return fluentC
private static void ConfigureStreamusDataAccess(Configuration configuration)
NHibernate.Context.WebSessionContext - analogous to ManagedWebSessionContext above, stores the current session in HttpContext.
You are responsible to bind and unbind an ISession instance with static methods of class CurrentSessionContext.
configuration.SetProperty("current_session_context_class", "web");
configuration.SetProperty("connection.isolation", "ReadUncommitted");
configuration.SetProperty("default_schema", "[Streamus].[dbo]");
configuration.SetProperty("generate_statistics", "true");
Here are screenshots of NHProf indicating multiple sessions on my CreateMultiple action and another screenshot of it not indicating multiple sessions. The first screenshot uses ISession passed in as a parameter and the second screenshot uses DependencyResolver:
解决方案 I'm not sure why it's happening, but you could write the registration like so:
containerBuilder.Register(x =& {
return x.Resolve&ISessionFactory&().OpenSession(); //set breakpoint here
}).As&ISession&().InstancePerHttpRequest();
and the set a breakpoint on your OpenSession() call, then debug though your code and see what the call stack looks like each time it gets called.
本文地址: &
我已经成功地实现使用Autofac的session-per-的HttpRequest。
我不满意我的实现,因为我要通过 DependencyResolver ,而不是依赖于通过AutoFac提供的参数。如果我靠的Isession 按AutoFac提供的参数,然后我收到一个警告与NHProf表明有在使用多个会话。如果我通过 DependencyResolver ,从NHProf警告消失,但使用感觉不正确的我。
我有其次这里列出的Autofac + MVC4.0准则:
我还使用本指南作为参考。它表明它应该能够接受的ISession作为构造参数:
下面是我如何建立我Autofac容器:
公共类AutofacRegistrations
{公共静态无效RegisterAndSetResolver() {变种containerBuilder =新ContainerBuilder();
containerBuilder.RegisterControllers(Assembly.GetExecutingAssembly());
//只产生一个会话工厂以往,因为它是昂贵的。
containerBuilder.Register(X =&新建NHibernateConfiguration()配置()BuildSessionFactory()。)SingleInstance()。
//其他的一切希望会议的每个HTTP请求的一个实例,因此表明: containerBuilder.Register(X => x.Resolve< ISessionFactory>()的openSession()) 。至于<&ISession的GT;()InstancePerHttpRequest()。
containerBuilder.Register(X => LogManager.GetLogger(MethodBase.GetCurrentMethod()DeclaringType)。)为& ILog的方式&()InstancePerHttpRequest();
containerBuilder.RegisterType&所述; NHibernateDaoFactory>()为& IDaoFactory方式&()InstancePerHttpRequest();
containerBuilder.RegisterType&所述; StreamusManagerFactory>()为& IManagerFactory方式&()InstancePerHttpRequest();
// containerBuilder.RegisterModule将所有所需的HTTP模块每个Web请求的生活方式,改变默认的控制器工厂,以支持到使用Autofac之一。
containerBuilder.RegisterModule(新AutofacWebTypesModule());
的IContainer容器= containerBuilder.Build();
DependencyResolver.SetResolver(新AutofacDependencyResolver(容器)); } }
这是我的基础类。注意注释掉的代码,原来接受会议作为参数:
公共抽象类StreamusController:控制器 {保护只读的ILog记录仪; 保护的新的只读的Isession会议;
保护StreamusController(ILog的记录,/ *的ISession会议* /) {如果(记录仪== NULL)抛出新的ArgumentNullException(“记录仪”);
//如果(会话== NULL)抛出新的ArgumentNullException(“会议”);
=记录仪记录;
// TODO:这是不是传递的ISession到控制器AutoFac有什么不同? 会议= DependencyResolver.Current.GetService<&ISession的GT;();
//会话=会议; }
我遇到不同与NHProf结果的基础上我是否有工作的Isession作为一个参数或通过DependencyResolver访问它。为什么呢?我的理解是,这两种方式应该是完全一样的!
有关参考,这里是我的懒惰NHibernateConfiguration / ISessionFactory实现。我不认为这是眼前的问题非常重要:
公共类NHibernateConfiguration
{公共FluentConfiguration配置() {字符串的ConnectionString = ConfigurationManager.ConnectionStrings [“默认”]的ConnectionString。
FluentConfiguration fluentConfiguration = Fluently.Configure() .Database(MsSqlConfiguration.MsSql2008.ConnectionString(的connectionString).ShowSql()。FormatSql()) .Mappings(CFG =&GT ; cfg.FluentMappings.AddFromAssemblyOf< UserMapping>()) .ExposeConfiguration(ConfigureStreamusDataAccess);
返回fluentC }
私有静态无效ConfigureStreamusDataAccess(配置配置) { // NHibernate.Context.WebSessionContext
- 类似于上面ManagedWebSessionContext,存储在HttpContext的当前会话。
//你有责任约束和类CurrentSessionContext的静态方法取消绑定一个ISession实例。
configuration.SetProperty(“current_session_context_class”,“网络”);
configuration.SetProperty(“connection.isolation”,“READUNCOMMITTED”);
configuration.SetProperty(“DEFAULT_SCHEMA”,“[Streamus] [DBO]。”);
configuration.SetProperty(“generate_statistics”,“真”); } }
下面是表示对我的CreateMultiple多个会话NHProf截图行动和它另一张截图不是指示多个会话。第一张截图使用的ISession传过来的参数和第二个屏幕使用DependencyResolver:
解决方案 我不知道为什么它的发生,但你可以写登记,像这样:
containerBuilder.Register(X => {返回x.Resolve< ISessionFactory>()的openSession(); //设置这里断点})为&的ISession>()InstancePerHttpRequest();
和设置一个断点在你的openSession()调用,然后调试虽然你的代码,看看有什么调用堆栈看起来每次被调用的时间等。
本文地址: &
扫一扫关注官方微信南京方言(是上是下)什么意思 &是上是下&_百度知道

我要回帖

更多关于 amp quot的意思 的文章

 

随机推荐