微软Unity-问题解决 [英] Microsoft Unity- Issue With Resolve

查看:151
本文介绍了微软Unity-问题解决的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望做这样的:

container.Resolve();

container.Resolve();

当它这样做,它要一个IDependency注入到底层的实体对象。然而,容器内存储的依赖性要求类型DependencyValue,被提供从一个DependencyFactory一个值的一个目的。所以长话短说,我遇到的问题是,我需要的时候统一创建类的实现IDependency,我将能够接管并插入自定义值不是在容器中的实例。

When it does this, its going to inject a IDependency into the underlying entity object. However, the dependency stored within the container requires an object of type DependencyValue, which is supplied a value from a DependencyFactory. So long story short, the issue I'm having is that I need to, when Unity creates the instance of class implementing IDependency, that I would be able to take over and insert a custom value not in the container.

这是可能的,或者是使用RegisterInstance在容器上,然后手动实例化对象,我最好的选择?我preFER使用配置文件来存储映射,然后添加一些逻辑参数实例。是什么ParameterOverrides是为了做什么?或者,我需要添加一个扩展这一点,还是什么?

Is that possible, or is my best bet to use RegisterInstance on the container and manually instantiate the objects? I prefer using the configuration file to store the mapping, and then add some logic for parameter instantiation. Is that what the ParameterOverrides is meant to do? Or do I need to add an extension for this, or what?

感谢。

推荐答案

你为什么不使用静态工厂扩展?

Why don't you use the static factory extension?

var container = new UnityContainer();
container.AddNewExtension()
         .Configure()
         .RegisterFactory(container =>
                          DependencyFactory.GetValue());

这篇关于微软Unity-问题解决的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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