UnityContainer 和构造函数参数
我有一个“Adapter”类,它包装一个名为“X_Session”的对象。此适配器需要 ILogger 和 ICacheManager。
我的想法是使用 Unity 定义此类,并让它解析作为构造函数输入放入的两个接口。
那么 X_Session 对象呢?它不是由 Unity 注册的,因为我需要自己创建它,因为它的构造函数需要我从 QueryString 收集的输入参数。
我是否解析 Adpater 类然后设置 X_Session 对象?还有其他更好的方法吗?
谢谢
I have an "Adapter" class that wraps an object called "X_Session". This adpater expects an ILogger and ICacheManager.
The way I thought of it is by defining this class with Unity and let it resolve both interfaces that are put in as constructor inputs.
What about the X_Session object? It is not registered by Unity, as I need to create it myself because its constructor requires input parameters that I gather from QueryString.
Do I resolve the Adpater class then set the X_Session object? Other better way?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
同样,使用抽象工厂很简单:
您只需在 Unity 中注册工厂即可。
Again, with an abstract factory is simple:
You have to register in Unity only the factory.
另一个想法是在运行时在 Unity 容器内注册 X_Session 对象,然后让 Unity 注入所有依赖项。
Another idea would be registering the X_Session object inside the Unity container at runtime, then having Unity injecting all the dependencies.