0

난 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 중 어느 쪽이 좋습니까?

답변

0

프로젝트를 실행하기 위해 전체 솔루션을 다운로드하려고 시도 했습니까? 이 코드의 단지 샘플이고, 당신이 전체 설치가 필요합니다 등 엔티티 클래스, 매핑, 저장소

와 프로젝트 VS 내가 http://www.sharparchitecture.net/에 갈 것이고 https://github.com/sharparchitecture 당신이 필요로하는 정확한 설정을 가지고 자신의 Northwind 예제 프로젝트를 다운로드합니다. Northwind 데이터베이스를 찾아 로컬 컴퓨터에 설치 한 다음 데이터베이스를 가리 키도록 NHibernate.config를 수정해야합니다.

+0

나는 책의 소스 코드를 다운로드했으나 그 책과 관련된 솔루션 파일이 아닌 것 같다. – chobo2

관련 문제