Unity 2 属性注入,如何将配置转换为流畅的语法?
我有一个 httpHandler 并使用 Unity 2 我想将依赖项注入到我的 HttpHandler 中。
我的代码如下所示:
public class MyHandler : BaseHandler
{
public MyHandler()
{
}
public IConfigurationManager Configuration
{
get;
set;
}
...
}
使用 web.config 我会像这样配置它(为了简单起见,省略了配置的其余部分):
<type type="MyHandler">
<typeConfig extensionType="Microsoft.Practices.Unity.Configuration.TypeInjectionElement, Microsoft.Practices.Unity.Configuration">
<property name="Configuration" propertyType="IConfigurationManager">
<dependency/>
</property>
</typeConfig>
</type>
我将如何使用流畅的语法做同样的事情?到目前为止,我尝试过的所有操作都会在处理程序触发时将属性设置为 null。
谢谢
I have a httpHandler and using Unity 2 I would like to inject a dependency into my HttpHandler.
My code looks like:
public class MyHandler : BaseHandler
{
public MyHandler()
{
}
public IConfigurationManager Configuration
{
get;
set;
}
...
}
Using the web.config I would configure it like this (left out the rest of the config for simplicity) :
<type type="MyHandler">
<typeConfig extensionType="Microsoft.Practices.Unity.Configuration.TypeInjectionElement, Microsoft.Practices.Unity.Configuration">
<property name="Configuration" propertyType="IConfigurationManager">
<dependency/>
</property>
</typeConfig>
</type>
How would I go about doing the same thing using fluent syntax? Everything I have tried so far leaves the property set to null when the handler fires.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
自 Unity 1.2 发布以来,ConfigureInjectionFor 已过时。
这应该有效:
ConfigureInjectionFor has been obsolete since Unity 1.2 was released.
This should work:
您必须调用
ConfigureInjectionFor
方法。编辑:
这是处理程序工厂的示例。它允许您创建处理程序
然后,您必须在 Web 应用程序中注册工厂(以允许 IIS 找到它)。您可以在此处找到更多详细信息。
You have to call the
ConfigureInjectionFor
method.EDIT:
Here is an example of Handler factory. It allow you to create your handler
Then, you have to register the factory in your web application (to allow IIS to find it). You can find more details here.