Host as service registrar - how to achieve?

Mar 28, 2008 at 12:41 PM
Edited Mar 28, 2008 at 12:43 PM
Hello,

My host has this contract:
[AddInContract]
public interface IHostContract : IContract
{
	void Register(IServiceContract service, Type serviceType);
	IServiceContract Resolve(Type serviceType);
}
I am trying to get one add-in (the provider) to register a service in the host and another add-in (the consumer) to use that service. The service contract looks like this:
[AddInContract]
[BaseClass(typeof(IServiceContract))]
public interface ISomeServiceContract : IServiceContract
{
	string GetValue(int i);
}
The implementation of this dummy service is in the provider add-in. For reference, the add-in code is:
[System.AddIn.AddIn("First Addin")]
[QualificationData("AppDomain", "Host")]
public class FirstAddIn : IModule
{
	public void Initialize(IHost host)
	{
		Console.WriteLine("Registering service from AppDomain '{0}'", AppDomain.CurrentDomain.FriendlyName);
		host.Register(new SomeServiceImpl(), typeof(ISomeService));
	}
}
 
[System.AddIn.AddIn("Second Addin")]
public class SecondAddIn : IModule
{
	public void Initialize(IHost host)
	{
		ISomeService someService = host.Resolve(typeof(ISomeService)) as ISomeService;
 
		if (someService != null)
		{
			Console.WriteLine("Calling service from AppDomain '{0}'", AppDomain.CurrentDomain.FriendlyName);
			Console.WriteLine(someService.GetValue(2));
		}
		else
		{
			Console.WriteLine("ERROR: service not found");
		}
	}
}
 
internal sealed class SomeServiceImpl : ISomeService
{
	public string GetValue(int i)
	{
		return "Here you go : " + i.ToString();
	}
}
The problem is, I can only get this to work if the provider add-in is loaded into the same AppDomain as the host (that's what the QualificationData is specifiying in the provider add-in). Otherwise, I get this error in the host's contract->view adapter:
System.IO.FileNotFoundException was unhandled by user code
  Message="Could not load file or assembly 'AddInView, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified."
Why does the host need access to the add-ins view in order to adapt the service? As a first step I included the ISomeService contract in the host, so it has full knowledge of that contract. As a second step, I want to move that service out into the provider add-in. However, I need to get past this problem first.

Am I doing something fundamentally wrong here?

Thanks,
Kent
Mar 31, 2008 at 10:01 AM
OK, I think I want my host to implement the IProfferServiceContract and IServiceProviderContract interfaces. I couldn't see any sample on this - are there any planned? Does the pipeline builder support these contracts?

Thanks,
Kent
Jul 9, 2008 at 4:11 PM
To answer my own question, see my post here: http://kentb.blogspot.com/2008/06/maf-gymnastics-service-provider.html