在我当前使用asp.net MVC 3(使用razor)的项目中,当我进行Ajax调用时,我必须将JS保留在视图页面上,因为我想使用Url.Action来生成URL.这意味着我无法将js代码拆分为.JS文件,是否有比我目前正在做的更好的解决方案.
我是整个城堡Windsor,Nhibernate,Fluent和Automapping堆栈的新手,所以请原谅我的无知.我不想在此发布另一个问题,因为似乎已经有大量问题试图解决Windsor nhib Isession管理问题,但到目前为止他们都没有解决我的问题.当我试图从我的存储库调用Db时,我仍然得到一个ISession已关闭的异常,这是我的容器设置代码.
container.AddFacility<FactorySupportFacility>()
.Register(
Component.For<ISessionFactory>()
.LifeStyle.Singleton
.UsingFactoryMethod(() => Fluently.Configure()
.Database(
MsSqlConfiguration.MsSql2005.
ConnectionString(
c => c.Database("DbSchema").Server("Server").Username("UserName").Password("password")))
.Mappings
(
m =>
m.AutoMappings.Add
(
AutoMap.AssemblyOf<Message>(cfg)
.Override<Client>(map =>
{
map.HasManyToMany(x => x.SICCodes).Table("SICRefDataToClient");
})
.IgnoreBase<BaseEntity>()
.Conventions.Add(DefaultCascade.SaveUpdate())
.Conventions.Add(new StringColumnLengthConvention(),new EnumConvention())
.Conventions.Add(new EnumConvention())
.Conventions.Add(DefaultLazy.Never())
)
)
.ExposeConfiguration(ConfigureValidator)
.ExposeConfiguration(BuildDatabase)
.BuildSessionFactory() as SessionFactoryImpl),
Component.For<ISession>().LifeStyle.PerWebRequest.UsingFactoryMethod(kernel => kernel.Resolve<ISessionFactory>().OpenSession()
));
Run Code Online (Sandbox Code Playgroud)
在我的存储库中,我注入private readonly ISession session;并使用它作为followes
public User GetUser(int id)
{
User u;
u = session.Get<User>(id);
if (u != null && u.Id > 0)
{
NHibernateUtil.Initialize(u.UserDocuments);
}
return u;
Run Code Online (Sandbox Code Playgroud)
在我的web.config里面<httpModules> …