2009-07-10 13 views
9

Tôi đã cấu hình này trong hibernate.cfg.xml:Nhà máy Proxy có cần thiết trong NHibernate không?

<?xml version="1.0" encoding="utf-8" ?> 
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> 
    <session-factory> 
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property> 
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property> 
    <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property> 
    <property name="connection.connection_string">Data Source=.\SQLEXPRESS;Initial Catalog=MyDB;Integrated Security=SSPI;</property> 
    <property name="show_sql">true</property> 
    </session-factory> 
</hibernate-configuration> 

Tôi vừa tạo một Class Library và tôi đã tạo ra một thử nghiệm tích hợp sử dụng MbUnit. Nó thất bại. Một phần của báo cáo (một trong những mà tôi nghĩ là đủ) goes here:

** NO TESTS WERE RUN (No tests found) ** 
TestCase 'M:IntegrationTests.RepositoryTests.ListAllPostsReturnsAListOfPost' 
failed: The ProxyFactoryFactory was not configured. 
Initialize 'proxyfactory.factory_class' property of the session-factory configuration section with one of the available NHibernate.ByteCode providers. 

Tôi đã đọc nhiều hướng dẫn và chưa thấy cấu hình máy proxy này. Việc xác định nó có thực sự cần thiết không? Nếu vậy, làm thế nào tôi có thể làm điều đó? Tôi có phải tham khảo một số thư viện khác không?

Trả lời

14

Nếu bạn đang sử dụng phiên bản mới nhất của NHibernate (2.1), bạn sẽ nhận thấy rằng mainline for NH doesn't have a dependency on castle để tạo proxy nữa, vì vậy tất cả các hướng dẫn bạn đã xem có lẽ đã lỗi thời.

Về cơ bản, bây giờ bạn có một vài lựa chọn về cách bạn muốn tạo proxy động, do đó, bạn cần định cấu hình rõ ràng trình tạo proxy nào bạn muốn sử dụng. Có thể tìm thấy các ví dụ trong số how-to post on forge này. Danh sách đầy đủ các tùy chọn được tham chiếu here.

P.S. nếu bạn muốn giữ mọi thứ đơn giản, chỉ cần sử dụng Castle vì các phiên bản cũ hơn của NHibernate đều sử dụng nó theo mặc định.

+0

Theo [câu trả lời này] (http://stackoverflow.com/a/8932549/326110), bạn thậm chí không cần phải định cấu hình proxy nữa. –