New Posts New Posts RSS Feed: Bootstrapping WCF
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Bootstrapping WCF

 Post Reply Post Reply
amarpai View Drop Down

Joined: 29-Jul-2013
Posts: 2
Post Options Post Options   Quote amarpai Quote  Post ReplyReply Direct Link To This Post Topic: Bootstrapping WCF
    Posted: 29-Jul-2013 at 3:51pm
We have an existing WCF service and would like to get the Cocktail/DevForce injection to work. The code is as follows:

public class MyWcfService : IMyWcfService
IMyUnitOfWork MyUnitOfWork;

   public Customer ProcessRequest(int id)
      Customer customer = await MyUnitOfWork.CustomerRepository.FindCustomer(id);
      return customer;

The MyUnitOfWork field is not getting resolved. This is because Cocktail is not bootstrapped. I have seen examples of using Cocktail with WPF and I am able to get that to work. But the WCF part is not working.

Has anyone done this before?

Back to Top
mgood View Drop Down

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 29-Jul-2013 at 4:28pm
First and foremost, don't use Cocktail on the server as-is. Many parts of Cocktail are not threadsafe and that includes the single shared MEF container. Cocktail is a client framework written with a single UI thread in mind. A server is a different animal all together starting with the fact that it is multi-threaded by design. 

The above won't work, because the WCF service is not created by MEF. You could call Composition.BuildUp(this) in the constructor to satisfy the imports, but again, don't do this on the server with Cocktial as-is, unless you want to create yourself a headache down the road.

If you only want to use the Compositon part of Cocktail on the server, the way to do that is to implement a threadsafe version of ICompositionProvider that sets up the MEF container per thread instead of a globally shared container. You can then call Compositon.SetProvider to configure Cocktail to use your threadsafe composition provider.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down