문제

Can an abstract class be used as the contract object between a 'Host' and a 'plugin'? The idea is that the plugin inherits the contract (we call it an adapter). We are also understanding that all participants in the framework must inherit MarshalByRefObject (MBRO). So, this is what we were thinking -

Host:

class Host : MarshalByRefObject
{
}

Contract:

public abstract class PluginAdapter : MarshalByRefObject
{
}

Plugin:

class myPlugin : PluginAdapter
{
}

All three exist in separate asm's. Our Host will create a new AppDomain for each plugin, and the PluginAdapter is created as follows:

{
    ObjectHandle instHandle = Activator.CreateInstance(
    newDomain, data.Assembly.FullName, data.EntryPoint.FullName);

    PluginAdapter adapter = (PluginAdapter)instHandle.Unwrap();
}

EDIT: where data is the concrete type of myPlugin.

We were wondering if this implementation of the framework would work. We have seen articles using an interface (IPlugin) for the plugin derivation, and a concrete class as the contract. Those articles would also say that an abstract class can be used, but no examples of that implementation given. Is it required that the contract be a concrete class?

EDIT: In this example by Richard Blewett - C# Reflection - he uses a much simpler implementation:

Contract:

public interface IPlugIn  
{  
    // do stuff  
}

Plugin:

public class PlugIn : MarshalByRefObject, IPlugIn  
{  
}

Now, if using an abstract class as the contract, the Plugin cannot inherit both the contract and MBRO. What, then, becomes the best implementation for a scalable plugin framework. Should we go ahead and implement remoting even though, initially, we are developing for single-machine operation? This project is expected to become distributed across a network, possibly across the Internet as well. We simply have not implemented Tcp yet because we are trying to get the basics of a plugin framework fully understood and operational.

Does it make sense to implement Tcp remoting on a single machine using loopback?

도움이 되었습니까?

해결책

Jetbrains는 다음 사소한 팀의 다음 사소한 릴리스에 MSBuild 4.5 지원을 추가 할 계획입니다 (이슈 TW-20629 ).

다른 팁

Provided "data.EntryPoint.FullName" is the full type name, the above code should work.

However, if you're trying to keep this type isolated in its own AppDomain, you should be careful here. By doing data.Assembly, you'll pull the assembly (and it's types) into your AppDomain, causing the types to be loaded in the executing AppDomain...

You may want to take a look at MAF (the Managed Addin Framework) which is an extensibility framework built into .NET for doing Addins. It is similar (and older) than MEF (Managed Extensibility Framework), but has more options as far as keeping plugins in their own app domain, among other things.

If data.EntryPoint.FullName refers to the concrete type myPlugin I don't see any reason why this wouldn't work (unless than having assembly loading issues in the other appdomain but that's a different issue).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top