Stephen Patten
Stephen Patten

Reputation: 6363

Is there a .NET IoC container that can load and unload assemblies

I'm beating my head against the wall trying to find a container that will accomplish this.

What I'd like to do is have a AS.NET website running and not unload / recycle the AppDomain when I deploy a new or updated business rule contained in an assembly. This implies that the folder is outside of the bin folder, and preferably above it, not under it (although I can live with that). The closet I've come to this so far is using Autofac and MEF, but it seems like there's no way to unload a previously loaded assembly.

Anybody have any resources they can point me to?

Thank you, Stephen

Upvotes: 3

Views: 676

Answers (2)

Alexei Levenkov
Alexei Levenkov

Reputation: 100527

You can not unload assemblies in .Net without unload whole AppDomain. So the only way to allow it is to load new assemblies into new AppDomains.

While it may be possible to build such IoC container that will marshal all requests to new AppDomains for many interfaces such code would put very significant restrictions on methods/objects exposed by the interfaces. Also many .Net objects can't cross AppDomain boundary (xml, UI/controls, HTML context, database related classes).

It is significantly easier to allow ASP.Net to deal with reloading of the AppDomain.

Upvotes: 3

TomTom
TomTom

Reputation: 62093

No, there is not. Because it is not possible to unload an assembly, only a total appdomain. THis is a .NET runtime limitation - and as every .NET IOC container has to live in the .NET runtime it can not bypass it.

If your imports are big enough isolating them in separate appdomains may be a good and viable idea.

Upvotes: 6

Related Questions