Pregunta

I've inherited a project which was running on a host who had set up Full Trust, as this is required for the Castle Windsor IoC. The new host, however, will only run in Medium Trust (as do most shared hosting providers), so I need to replace Windsor with another IoC.

Being fairly new to IoC, I'm not sure which framework(s) are best to use under Medium Trust and with the Service Locator model.

An example of existing registration code is as follows:

IWindsorContainer container = new WindsorContainer();
ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(container));

container.RegisterControllers(typeof(HomeController).Assembly);

container.Register(
    Component.For(typeof(IEntityDuplicateChecker))
        .ImplementedBy(typeof(EntityDuplicateChecker))
        .Named("entityDuplicateChecker"));

container.Register(
    AllTypes
        .FromAssemblyNamed("Salient.Website.Data")
        .Pick()
        .WithService.FirstNonGenericCoreInterface("Salient.Website.Core"));

container.Register(
    AllTypes
    .FromThisAssembly()
        .Pick()
        .WithService.FirstNonGenericCoreInterface("Salient.Website.ApplicationServices"));

ServiceLocator.SetLocatorProvider(() => new WindsorServiceLocator(container));

It would save me a lot of trial-and-error with each framework, if I had some guidance of which ones will be suitable, work under medium trust shared hosting, and hopefully an example of translating the above to get started.

¿Fue útil?

Solución

The partial trust requirement of your hoster is odd, since Microsoft has provided guidance to hosters that they should migrate away from Medium Trust and use proper OS-level isolation instead (see here and here and here). The official position of the ASP.NET team is that Medium Trust is obsolete, which means that new features and frameworks wont be tested for partial trust support and bugs in that area won't get fixed.

Nevertheless, there are other frameworks that will run in partial trust:

  • Simple Injector (which I maintain) is designed and tested for partial trust scenarios.
  • Ninject has special builds for medium trust environments.

There might be others, but these are the ones I know of.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top