是否使数据访问服务成为单一的单身人士的好主意? [英] Is making data access services unity singletons a good idea?

查看:80
本文介绍了是否使数据访问服务成为单一的单身人士的好主意?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Prism WPF应用程序,它使用服务从Web API或直接通过EF读取数据。我想将服务注册到Unity容器中,并且我认为拥有它们是一个非常好的主意。应该只有一个线程使用任何一个服务,因为它是一个用户的桌面应用程序。



有什么可以反对让他们成为单身人士吗?它们非常轻巧,因此内存占用(对于它们来说)没有问题。



我尝试过:



没什么,只是征求意见。

I have a Prism WPF app that uses services to read data from either a web API or directly, via EF. I want to register the services into the Unity container, and am thinking having them singletons is a pretty good idea. There should only ever be one thread using any one service, as it's a desktop app with one user.

Is there anything against making them singletons? They are extremely lightweight, so memory footprint (for them) is no issue.

What I have tried:

Nothing, just asking for advice.

推荐答案

只要他们不在班级本身存储状态你应该是好的,即方法只使用方法的局部变量。
As long as they don't store state in the class itself you should be ok, ie if methods only use variables local to the method.


这篇关于是否使数据访问服务成为单一的单身人士的好主意?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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