使用 Autofac 将服务注入 NHibernate 的 IUserType 实现中

发布于 2024-09-28 07:39:58 字数 522 浏览 0 评论 0原文

我正在使用 NHibernate 将以下类映射到我的 ASP.NET MVC 应用程序中的 Oracle 数据库:

public class User
{
    // Needs to be encrypted/decrypted when persisting
    public virtual string Question { get; set; }
}

根据我发现的几个示例,我想使用 NHibernate 的 IUserType 的实现来在数据持久化时将其转换为或从我的数据库示例检索。

由于我已经编写了一个 EncryptionService 类来处理应用程序其他部分中的数据加密,因此我想将其注入到我的用户类型中。有没有办法使用 Autofac 对 IUserType 执行构造函数注入?

I'm using NHibernate to map the following class to an Oracle database in my ASP.NET MVC application:

public class User
{
    // Needs to be encrypted/decrypted when persisting
    public virtual string Question { get; set; }
}

Following several examples that I've found, I would like to use an implementation of NHibernate's IUserType to transform my data when it is persisted to or retrieved from my database example.

Since I have already written an EncryptionService class to handle data encryption in other parts of my application, I would like to inject it into my user type. Is there a way to perform constructor injection on an IUserType using Autofac?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

穿透光 2024-10-05 07:39:58

NHibernate 负责创建 IUserType 实现的实例。如果您希望进行此配置,您可以从 AutoFac 容器查询服务(显然这不是依赖注入,更多的是服务定位器)。或者您可以实现 IConfigurable,它允许您接受参数字典。这些参数之一可以是类名。

NHibernate is responsible for creating instances of IUserType implementations. If you want this configurable, you could query the service from the AutoFac container (obviously this isn't dependency injection, more of service locator). Or you could implement IConfigurable, which allows you to take in a Dictionary of parameters. One of those parameters could be a class name.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文