tags:

views:

110

answers:

1
[ClassInterface(ClassInterfaceType.None)]
[Guid("12C969B3-330D-4230-ACDA-F9BED3286B1E")]
[ProgId("Lib.Class")]
public class MyService : ServicedComponent, IMyService
{
      ...
}

Unit Test:

MyService target = new MyService ();

This code creates a TransparentProxy object, which is how the component should run in production.

How can I create an instance of the class in-process and local, such that I can inject its dependencies?

A: 

I don't like it, but you can use conditional compilation statements, Debug/Release or I use DebugComPlus/Debug/Release (where only Debug is not a ServicedComponent). Note that you should implement IDisposable in the Debug condition because you'll have to call Dispose on ServicedComponent for real code, and the Dispose method won't be there if it's not a ServicedComponent.

Otherwise I really recommend just testing it through COM+ because that's what you'll be running in real life, and you'll encounter issues with COM+ in production that you'll miss if you test outside of COM+. That's the way we had it now on one project I am on, and there were many difficult to find bugs because of that. Personally always test through COM+ now.

Richard Hein