NHibernate中是否需要代理工厂? [英] Is Proxy Factory necessary in NHibernate?

查看:100
本文介绍了NHibernate中是否需要代理工厂?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在hibernate.cfg.xml中具有以下配置:

I've this configuration in the hibernate.cfg.xml:

<?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>

我刚刚创建了一个类库,并使用MbUnit创建了集成测试.它失败.报告的一部分(我认为足够了)在这里:

I've just created a Class Library and I've created an integration test using MbUnit. It fails. A part of the report(the one which I think is enough) 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.

我已经阅读了许多教程,还没有看到此代理工厂配置.指定它真的有必要吗?如果是这样,我该怎么办?我必须参考其他图书馆吗?

I have read many tutorials and haven't seen this proxy factory configuration. Is specifying it really necessary? If so, how can I do that? Do I've to reference some other library?

推荐答案

如果您使用最新版的NHibernate(2.1),则会注意到

If you're using the latest of NHibernate(2.1), you'll notice that mainline for NH doesn't have a dependency on castle for proxy generation anymore, so all those tutorials you've been looking at are probably out of date.

基本上,现在您可以选择创建动态代理的方式,因此您需要明确配置要使用的代理生成器.可以在以下方法中找到示例-在伪造中发帖.选项的完整列表在此处引用.

Basically, you now have a few choices of how you want your dynamic proxies created, so you'll need to explicitly configure which proxy generator you want to use. Examples can be found in this how-to post on forge. A full list of the options is referenced here.

P.S.如果您想保持简单,只需使用城堡,因为NHibernate的旧版本都已使用默认情况下.

P.S. if you want to keep things simple, just use Castle as the older versions of NHibernate all used it by default.

这篇关于NHibernate中是否需要代理工厂?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆