IIS hosted Wcf service with assemby resolution is possible?
Is it possible to load assemblies via assembly resolve event in iis hosted wcf service. I don't want load assemblies via GAC or bin folder. Is it possible? thank开发者_运维技巧s.
I don't think you can use the AppDomain.AssemblyResolve event, but what you might try is using MEF to resolve actual implementation using a DirectoryCatalog.
So your SVC code behind (or you can remove the code behind and point your SVC to a class in a separate assembly) would look something like this (untested). I've not tried this specific method, but I don't see any reason it wouldn't work.
public class YourServiceClass : YourServiceContract
{
[Import]
private IContract Implementation { get; set; }
private DirectoryCatalog _directoryCatalog = null;
private CompositionContainer _container = null;
public YourServiceClass()
{
_directoryCatalog = new DirectoryCatalog(YourDirectoryPathHere);
_container = new CompositionContainer(_directoryCatalog);
_container.ComposeParts(this);
}
//Operation
public void DoSomething()
{
Implementation.DoSomething();
}
}
You could also move the MEF code to a base class if that makes sense. If you're new to MEF, here's a tutorial using MEF with a DirectoryCatalog.
精彩评论