c#:在哪里放置我的 API 以及什么应该放入 MyCOmpanyName.MyProduct.Core(核心)命名空间?
谁能帮我提供一些重构建议。
我有我的应用程序,它在命名空间中 - 这些命名空间我很满意。
MyCompany.MyProduct.Web (for the web app)
MyCompany.MyProduct.Windows (for the windows app)
这些应用程序需要调用我的 API .. 该 API 专门用于此应用程序,但独立存在。目前我的形式如下。
MyCompany.MyProduct.Api
但我真的不喜欢它......我想也许最好把它放进去
MyCompany.MyProduct.Core
这是一个好方法吗?
在 Core 下,我将有枚举、异常类等,
所以这些实际上是
MyCompany.MyProduct.Core.Enums.DaysOfWeek (DaysOfWeek is an example)
MyCompany.MyProduct.Core.Exceptions.ConnectionException (just an example)
Core 是一个好主意吗?里面应该放什么。???
如果我有一个名为 CreateSchedule 的命令,它位于 Schedule 类下,它是我的 api 的一部分,那么对于包括方法等在内的完整命名空间来说,这是一个好主意,
MyCompany.MyProduct.Core.Schedule.CreateSchedule ???
我假设我将所有枚举/异常放在根(即核心)下全局特定于我的 api。我的应用程序可以使用 API 中的枚举/异常,这是一个好的做法吗?这就是我目前的做法。如果我有一个仅特定于某个类的枚举,我是否将其保留在根(核心)中,或者更好地放置它,
MyCompany.MyProduct.Core.Schedule.Enums
我希望有人可以帮助我,
提前致谢
can anyone help me with bit of refactoring advice.
I have my App which i have in the namespace - these namespaces i am happy with.
MyCompany.MyProduct.Web (for the web app)
MyCompany.MyProduct.Windows (for the windows app)
these apps need to call my API .. The API is specifically for this application but lives separately. Currently I have it in the following form.
MyCompany.MyProduct.Api
But i really don't like it... i was thinking maybe better to put it in
MyCompany.MyProduct.Core
Is this a good way?
Under Core i will have Enums, Exception Classes etc
So these would be actually
MyCompany.MyProduct.Core.Enums.DaysOfWeek (DaysOfWeek is an example)
MyCompany.MyProduct.Core.Exceptions.ConnectionException (just an example)
Is Core a good idea and what should go in there.????
If I have a command called CreateSchedule which is under the class Schedule which is part of my api then what would be a good idea for the complete namespace including method etc
MyCompany.MyProduct.Core.Schedule.CreateSchedule ???
I presume i put under the ROOT (i.e. CORE) all enums / exceptions that are globally specific to my api. Is it good practice that my app can use Enums /Exceptions from my API - this is how i currentlt have it. if i have an enum that is specific only to a class do i keep it there in ROOT (core) or better to put it
MyCompany.MyProduct.Core.Schedule.Enums
I hope someone can help me on this
thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为,如果枚举仅适用于特定类,那么使枚举位于该类内(即不在根级别)是有意义的。例如,将 DaysOfWeek 放在 Schedule 类中是有意义的。
“Core”肯定比“Api”好,因为它是一个缩写词,所以看起来有点奇怪。
我不确定是否有异常的命名空间(即 MyCompany.MyProduct.Core.Exceptions.xxx)。我宁愿将异常类作为生成它们的类的同级。
I think if an enum applies to only a specific class, then it makes sense to make the enum be within that class (i.e. not at the root level). For exampe, it makes sense for DaysOfWeek to be within the Schedule class.
"Core" is certainly better than "Api", which sort of looks weird since it's an acronym.
I am not sure about having a namespace for Exceptions (i.e. MyCompany.MyProduct.Core.Exceptions.xxx). I would rather put the exception classes as siblings of the class from which they are generated.