using a foundational service at biz module

Topics: Web Client Software Factory, Project Management Forum, User Forum
Jun 14, 2007 at 1:45 PM
Edited Jun 14, 2007 at 1:47 PM
1st: my english is really bad, so..

i already search at WCSF.chm, reference implementation, quick starts and so on, i've not found any sample about it..

so, i've build a service (FirstServiceAgent), on my foundational module, it's sucesfuly added on GlobalServices,
my question is:
How to use a service at Busines Module?
i mean, i would like to use at SomeController class at biz module the statement:


  1. Is that the rigth way to use a service?
  2. To use it (IFirstServiceAgent), i'll should add reference to the foundational module, is the rigth way to do that?
  3. Even if that way is the wrong way... How can i receive or have access to the "Global Service Container"?

some help??
Jun 14, 2007 at 2:19 PM
Actually, your English is pretty good :)

You could use the container as a Service Locator and fetch the IFirstAgentService as you show in your example, but a better approach would be to let the Composite Web Application Block inject the dependency in your Application Controller class for you.

Check the documentation at:

Inspecting the Software Assets > Patterns for Web Client Applications > Dependency Injection

Either in the constructor or via a property you can use the ServiceDependency Attribute to have the service automatically injected into the controller for you.

public class MyController
    private IFirstServiceAgent  _firstServiceAgent;
    public IFirstServiceAgent FirstServiceAgent
        set { _firstServiceAgent = value; }

The trick here is that the Controller Class needs to be created by the Composite Web Application Block ( ObjectBuilder ), which typically means somewhere in your View or Presenter Class you are injecting the Controller, which will in turn create the Controller and inject the FirstServiceAgent into it:

public class MyPresenter : Presenter<IMyView>
    private MyController  _controller;
    public MyController Controller
        set { _controller = value; }

If you check out the Bank Reference Implementation ( sample ) that comes with the Web Client Software Factory, it will give you an example of how Dependency Injection works.




David Hayden
Microsoft MVP C#
Jun 14, 2007 at 3:50 PM
ok, thanks for your help!

I'll use the ServiceDependency approach, it's cleaner!

This doubt come out cause the Bank Reference Implementation, or even Module Quick Start, have not a situation where;
a biz module has dependence (reference to another dll/project ) of a foundational module in design time..
and its needed, cause we have to use the interface of service agent (IFirstServiceAgent) anyway.

thanks a lot!

by the way, WCSF rocks!