structuremap

How do I use Structuremap 3 with objects that aren't friendly to constructor injection?

南楼画角 提交于 2019-12-07 22:06:49
问题 I'm moving from StructureMap 2.x to 3.x. One major change is that using ObjectFactory results in the following warning: 'StructureMap.ObjectFactory' is obsolete: 'ObjectFactory will be removed in a future 4.0 release of StructureMap. Favor the usage of the Container class for future work' So in most cases, the resolution is fairly easy: pass through IContainer as a constructor. Unfortunately this is not feasible for ASMX web serivces or attributes, both of which require a default constructor.

What's the difference between AddConcreteType and TheDefaultIsConcreteType in StructureMap?

戏子无情 提交于 2019-12-07 21:45:02
问题 I'm setting up StructureMap and it seems like everything I want to do there are two ways to do it and it's unclear to me what the difference is between them. For instance, what's the difference between these two lines: StructureMapConfiguration.ForRequestedType<IConsumer>().AddConcreteType<Consumer>(); StructureMapConfiguration.ForRequestedType<IConsumer>().TheDefaultIsConcreteType<Consumer>(); Similarly, what's the difference between using AddInstanceOf and ForRequestedType? 回答1:

Rhino.Security and IEntityInformationExtractor

让人想犯罪 __ 提交于 2019-12-07 21:15:34
问题 I've recently downloaded Rhino.Security and I am trying to implement permissions on a entity. Since I like Ninject (v2) I would like to put together a simple example to start with. In my NinjectModule I've bound the repository and the services: Bind<ISessionFactory>() .ToProvider(new SessionFactoryProvider()) .InSingletonScope(); Bind<ISession>().ToProvider(new SessionProvider()) .InSingletonScope(); Bind<IAuthorizationRepository>() .To<AuthorizationRepository>() .InSingletonScope(); Bind

Using WebApi and structure map dependency injection

主宰稳场 提交于 2019-12-07 18:52:06
问题 Although there are so many question on stack overflow which tends similar to my this question but no one is resolving my problem I was using an MVC4 internet application wherein i had few MVC controller and for dependency injection i was using Structure map . Although dependency injection works fine with MVC controller but when i added an WebApi controller in the same MVC internet application and using the same parameter in constructor of WebApi controller as what i am using in MVC controller

Selective IPrincipal Injection via StructureMap with SignalR

时光怂恿深爱的人放手 提交于 2019-12-07 18:37:32
问题 StructureMap is configured to inject HttpContext.Current.User when an IPrincipal is requested for any ASP.NET MVC web request, like so: For<IPrincipal>().Use(x => HttpContext.Current.User); But when my SignalR hub asks for a service that depends on an IPrincipal , injection fails because HttpContext.Current is null. Instead, SignalR already has a HubCallerContext property that exposes the current IPrincipal via Context.User . How do I configure StructureMap to always inject a valid IPrincipal

Ninject 3.0 MVC kernel.bind error Auto Registration

半城伤御伤魂 提交于 2019-12-07 16:39:16
问题 Getting and error on kernel.Bind( scanner => ... "scanner" has the little error line under it in VS 2010. Cannot convert lambda expression to type 'System.Type[]' because it is not a delegate type Tyring to Auto Register like the old kernel.scan in 2.0. I can not figure out what i am doing wrong. Added and removed so many Ninject packages. completely lost, getting to be a big waste of time. using System; using System.Web; using Microsoft.Web.Infrastructure.DynamicModuleHelper; using Ninject;

Is having a wrapper for your IoC a good idea?

瘦欲@ 提交于 2019-12-07 13:36:44
问题 I have been using StructureMap for more than a year now. And all this time I used to have a wrapper class called IoC which looked like this class IoC { public static T GetInstance<T>() { return (T)GetInstance(typeof(T)); } public static IEnumerable<T> GetAllInstances<T>() { return ObjectFactory.GetAllInstances<T>(); } public static IEnumerable GetAllInstances(Type type) { return ObjectFactory.GetAllInstances(type); } public static object GetInstance(Type type) { return ObjectFactory

Using StructureMap, is one of these project organizations better than another?

半世苍凉 提交于 2019-12-07 10:13:44
问题 I'm starting to work with StructureMap on a windows application project. In working on learning the basics, I found 2 ways to arrange my solution that accomplish the same goal, and I'm wondering if anyone can comment on if one of these 2 seems like a better option, and why. The goal here was to use IOC so that I could use 2 services without taking dependencies on them. So I I created interfaces in my Business Layer, and then implemented those interfaces in my Infrastructure project and

How to get the Structuremap IContainer instance from Asp.Net MVC 5 Dependency Resolver

我的未来我决定 提交于 2019-12-07 04:51:37
问题 I am using Structuremap as my Dependency Resolver. I am trying to implement Container Per Request Pattern on my Global.asax.cs file. public IContainer Container { get { return (IContainer)HttpContext.Current.Items["_Container"]; } set { HttpContext.Current.Items["_Container"] = value; } } public void Application_BeginRequest() { Container = ObjectFactory.Container.GetNestedContainer(); } As the ObjectFactory will not be supported in the future versions of Structuremap I would like get access

Can I replace the call to Activator.CreateInstance() in NHibernate?

落爺英雄遲暮 提交于 2019-12-06 14:39:02
问题 Is there a way to replace the call to Activator.CreateInstance() used inside NHibernate 2.0.1GA to construct the entities? Ideally I'd like to replace it with StructureMap.ObjectFactory.GetInstance(). 回答1: You can't do this easily with constructor injection. The NHibernate internals may need to create a proxy object inherited from your domain class with Lazy loading code etc. sprinkled in there, so, as far as I know, there's no simple option to override the construction of your object. You