结构图单例对象重新分配
我有一个由结构图管理的单例对象(注册为单例)。然后,我使用 automapper 将 DTO 对象映射到单个对象,如下所示:
_singletonObject = Mapper.Map<SingletonObject, DTOObject>();
automapper 实例工作正常,并在 _singletonObject 中分配相关属性。然而,赋值似乎取消了结构图中单例对象的关联。
在上面的赋值之后,如果我使用:
var singletonObject = ObjectFactory.Getinstance<SingletonObject>();
该对象似乎返回一个新对象?我做错了什么吗?
I have a singleton object (registered as singleton) that is managed by structuremap. I then use automapper to map a DTO object to the single objects as follows:
_singletonObject = Mapper.Map<SingletonObject, DTOObject>();
The automapper instance works fine and assigns the relevant properties within the _singletonObject. However the assignment seems to disassociate the singleton object in structuremap.
After the assignment above if I use:
var singletonObject = ObjectFactory.Getinstance<SingletonObject>();
The object is seems to return a new object? Am I doing something completely wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于其他有周五时间的人,您可以按如下方式映射:
注意没有返回值,因此没有分配!
For anyone else who is having a Friday moment you can map as follows:
Note no return value and hence no assignment!