structuremap

Comparing Castle Windsor, Unity and StructureMap

二次信任 提交于 2019-11-27 02:38:15
In a follow up to Krzysztof’s statement that Windsor does a lot more than other IoC’s, I wanted to understand how these IoC’s stack up against each other and the benefits/additional facilities that castle Windsor provides. Are there any comparisons? Can someone help me understand the additional features that Castle Windsor provides over other IoC’s Mauricio Scheffer See here and here for a pretty thorough technical comparison of several IoC containers, although somewhat outdated by now (they're from before Windsor 2.0) However, I don't think there are really any vital features that Windsor

WebAPI + APIController with structureMap

与世无争的帅哥 提交于 2019-11-27 01:49:16
问题 Im trying to use StructureMap to initialize my ValuesController that derivate from ApiController but i'm getting an exception that says: The IControllerFactory '...CustomControllerFactory' did not return a controller for the name 'api'. Here is the code.. public class CustomControllerFactory : DefaultControllerFactory { protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType) { if (controllerType == null) return null; return (Controller

NHibernate and Structure Map

走远了吗. 提交于 2019-11-27 00:24:28
问题 So I really like working with NHibernate but always used Spring.Net with it. I recently came across StructureMap by Jeremy Miller and really like it better than Spring.Net. On his StructureMap site he promises an example on how to use NHibernate and StructureMap together. Unfortunately he has not had time to do it (or I can't find it). So does anyone have an example on how to handle the NHibernate Session with StructureMap? 回答1: So, I apologize that we did not get the NHibernate with

Best way to use StructureMap to implement Strategy pattern

。_饼干妹妹 提交于 2019-11-26 17:47:05
My web app has some slight variations in business logic and presentation logic depending on the type of user that is logged in. It seems like getting variations by injecting different concrete classes based on the user type is a good fit for DI. So I'm wondering what features of StructureMap I should use to achieve this (or if I'm way off base on the purposes of DI). (I just learned that Profiles are not the way to accomplish this because setting the Profile isn't a per-thread operation: Are StructureMap profiles thread safe? ) EDIT Is this the way to go about this? public class HomeController

StructureMap Beginner | Property Injection

↘锁芯ラ 提交于 2019-11-26 16:39:21
问题 Part of this question was already asked here : structuremap Property Injection but the answer was never given. With StructureMap, is it possible to do Property Injection such that class SomeController : Controller { public IService Service { get; set; } } gets injected properly? I am a 回答1: StructureMap supports setter/property injection. So you could do the following: public class SomeController : Controller { [SetterProperty] public IService Service { get; set; } } and then: ObjectFactory

StructureMap Auto registration for generic types using Scan

杀马特。学长 韩版系。学妹 提交于 2019-11-26 16:31:44
问题 I've got an interface: IRepository<T> where T : IEntity while im knocking up my UI im using some fake repository implementations that just return any old data. They look like this: public class FakeClientRepository : IRepository<Client> At the moment im doing this: ForRequestedType<IRepository<Client>>() .TheDefaultIsConcreteType<FakeRepositories.FakeClientRepository>(); but loads of times for all my IEntities. Is it possible to use Scan to auto register all my fake repositories for its

How to use Container instead of ObjectFactory in StructureMap ServiceActivator?

牧云@^-^@ 提交于 2019-11-26 15:53:16
问题 When implementing DI in WebAPI with StructureMap, we used the ServiceActivator found in Configuring Dependency Injection with ASP.NET WebAPI 2.1 WebAPI + APIController with structureMap public class ServiceActivator : IHttpControllerActivator { public ServiceActivator(HttpConfiguration configuration) {} public IHttpController Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType) { var controller = ObjectFactory.GetInstance(controllerType) as

Null User on HttpContext obtained from StructureMap

巧了我就是萌 提交于 2019-11-26 14:57:19
问题 Ok, my previous question/setup had too many variables, so I'm stripping this down to it's bare bones components. Given the code below using StructureMap3... //IoC setup For<HttpContextBase>().UseSpecial(x => x.ConstructedBy(y => HttpContext.Current != null ? new HttpContextWrapper(HttpContext.Current) : null )); For<ICurrentUser>().Use<CurrentUser>(); //Classes used public class CurrentUser : ICurrentUser { public CurrentUser(HttpContextBase httpContext) { if (httpContext == null) return; if

StructureMap singleton usage (A class implementing two interface)

大憨熊 提交于 2019-11-26 13:02:28
问题 public interface IInterface1 { } public interface IInterface2 { } public class MyClass : IInterface1, IInterface2 { } ... ObjectFactory.Initialize(x => { x.For<IInterface1>().Singleton().Use<MyClass>(); x.For<IInterface2>().Singleton().Use<MyClass>(); }); var x = ObjectFactory.GetInstance<IInterface1>(); var y = ObjectFactory.GetInstance<IInterface2>(); I get two different MyClass instances with the above code. How can I get one? 回答1: You can use the Forward<,>() registration to tell

Comparing Castle Windsor, Unity and StructureMap

孤者浪人 提交于 2019-11-26 10:09:54
问题 In a follow up to Krzysztof’s statement that Windsor does a lot more than other IoC’s, I wanted to understand how these IoC’s stack up against each other and the benefits/additional facilities that castle Windsor provides. Are there any comparisons? Can someone help me understand the additional features that Castle Windsor provides over other IoC’s 回答1: See here and here for a pretty thorough technical comparison of several IoC containers, although somewhat outdated by now (they're from