简体   繁体   English

在CAB中,服务是其自己的模块吗?

[英]In CAB is a service its own module?

I'm learning Composite Application Block and I've hit a rock about services. 我正在学习“复合应用程序块”,并且在服务方面也步履维艰。 I have my shell application in its own solution, and of course a test module in its own solution (developed and testing completely independent and external of the shell solution). 我在自己的解决方案中有我的shell应用程序,当然也有它自己的解决方案中的测试模块(开发和测试完全独立于shell解决方案,并且在shell解决方案之外)。 If I created a service named "Sql Service", would I need to put this in its own library, so that both the shell and the module know the types? 如果我创建了一个名为“ Sql Service”的服务,是否需要将其放在自己的库中,以便外壳程序和模块都知道类型?

If that's the case, then for good practice, should I put the service project in the shell solution, or external just like a module (in its own solution), even though it's not loaded as a module? 如果是这种情况,那么出于良好实践,我是否应该将服务项目放在外壳解决方案中,还是将外部项目当作模块(在其自身的解决方案中),即使它没有作为模块加载?

Then, what about references? 那参考呢? Should the shell reference this directly, add then add the service? 外壳程序应该直接引用它,然后添加然后添加服务吗? Or load it as a module and add the service? 还是将其作为模块加载并添加服务?

Where should I create my services? 我应该在哪里创建服务? Should I reference or load as modules? 我应该作为模块引用还是加载?

If you have a service that you want to expose to two different assemblies, then what you should do is define the interface for that service in a separate assembly and share that between the two. 如果您有要公开给两个不同程序集的服务,那么您应该做的是在单独的程序集中定义该服务的接口并在两者之间共享。 Generally speaking, I always put services in their own assembly (project) and I put the interface definitions to those services in a separate assembly (project). 一般来说,我总是将服务放在自己的程序集(项目)中,并将接口定义放在那些服务中的单独程序集(项目)中。

In the specific case of the CAB I would avoid exposing much of anything to the Shell unless it is absolutely necessary - only if the Shell itself has to use the service would I reference it in the Shell. 在CAB的特定情况下,除非绝对必要,否则我将避免向Shell公开太多内容-仅当Shell本身必须使用该服务时,我才会在Shell中引用它。 The Shell should be bare-bones; 外壳应该是准系统。 it exists so that modules can show their own elements to the user. 它的存在是为了使模块可以向用户显示自己的元素。 Individual modules can worry about referencing and utilizing the specific services. 各个模块可能会担心引用和利用特定服务。

As far as solution organization: Generally, when I am working on a CAB application, everything is in one solution. 就解决方案组织而言:通常,当我在处理CAB应用程序时,一切都在一个解决方案中。 I have rarely had need for separate solutions. 我很少需要单独的解决方案。 Separate projects, yes - but all under one umbrella solution. 是的,单独的项目-但是全部归于一个总括解决方案。

In addition to Chris's answer, the only way that your shell would come to know about your service, is if you have a service dependency in the shell on your service and you have added the service to your root workitem. 除了Chris的答案之外,您的shell唯一了解您的服务的方法是,如果您的服务的shell中具有服务依赖项,并且已将该服务添加到根工作项中。

So in the shell you would have code something like 因此,在外壳中,您将拥有类似以下内容的代码

private ISqlService sqlService; 私有ISqlService sqlService;

[ServiceDependency Required=false] public ISqlService SqlService { get { return sqlService; [ServiceDependency Required = false] public ISqlService SqlService {get {return sqlService; } set { sqlService = value; }设置{sqlService = value; } } }}

In the SqlService class (which should be inherited from the WorkItemController class) you would have something like 在SqlService类(应从WorkItemController类继承)中,您将遇到类似

_rootWorkItem.Services.AddNew(); _rootWorkItem.Services.AddNew();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM