난 NHibernate에 요리 책 3.0 유동성 가이드를 판독하고 난 (자체 요리 책은 여러 가지 방법이 있음)구성 중 어느 것을 사용해야합니까? 유창한 지도서 또는 요리 책 3.0에서? (
유창함 자 NHibernate 가이드에게
private static ISessionFactory CreateSessionFactory()
{
return Fluently.Configure()
.Database(
SQLiteConfiguration.Standard
.UsingFile("firstProject.db")
)
.Mappings(m =>
m.FluentMappings.AddFromAssemblyOf<Program>())
.ExposeConfiguration(BuildSchema)
.BuildSessionFactory();
}
private static void BuildSchema(Configuration config)
{
// delete the existing db on each run
if (File.Exists(DbFile))
File.Delete(DbFile);
// this NHibernate tool takes a configuration (with mapping info in)
// and exports a database schema from it
new SchemaExport(config)
.Create(false, true);
}
요리 책 3.0 PG를 사용되어야하는 하나의 I 다소 혼란하고 76) 웹 요청
1. In the hibernate-configuration section of web.config, add the current_
session_context_class property with a value of web.
2. If it doesn't exist already, add a new Global application class (Global.asax).
3. In Global.asax, add these using statements.
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Context;
4. Create a static property named SessionFactory.
public static ISessionFactory SessionFactory { get;
private set; }
5. In the Application_Start method, add the following code.
protected void Application_Start(object sender, EventArgs e)
{
log4net.Config.XmlConfigurator.Configure();
var nhConfig = new Configuration().Configure();
SessionFactory = nhConfig.BuildSessionFactory();
}
6. In the Application_BeginRequest method, add the following code.
protected void Application_BeginRequest(object sender, EventArgs e)
{
var session = SessionFactory.OpenSession();
CurrentSessionContext.Bind(session);
}
7. In the Application_EndRequest method, add the following code:
protected void Application_EndRequest(object sender, EventArgs e)
{
var session = CurrentSessionContext.Unbind(SessionFactory);
session.Dispose();
}
그런 다음 그들은 이것을 사용하여 실행합니다. 나는 일반적으로 asp.net MVC 응용 프로그램에서이 코드를 삽입 할 위치를 유창 자습서
Guid productId = new Guid(Request["id"]);
Eg.Core.Product product;
var session = Global.SessionFactory.GetCurrentSession();
using (var tran = session.BeginTransaction())
{
product = session.Get<Eg.Core.Product>(productId);
tran.Commit();
}
Page.Title = product.Name;
Label1.Text = product.Name;
Label2.Text = product.Description;
은 또한 좀 혼란 스러워요. 저장소 패턴을 ninject (DI 주입)와 함께 사용하려고합니다.
두 가지 방법으로 ninject 및 저장소 패턴과 함께 작동시키는 방법을 잘 모르겠습니다.
리포지토리 패턴과 Di 중 어느 쪽이 좋습니까?
나는 책의 소스 코드를 다운로드했으나 그 책과 관련된 솔루션 파일이 아닌 것 같다. – chobo2