structuremap

How can I determine if StructureMap has loaded the same Registry multiple times?

自作多情 提交于 2019-12-06 13:16:58
问题 We are diagnosing an issue which seems to be related to StructureMap and a Registry. A large application of ours is loading a registry, but is experiencing some interesting side-effects. Without going into all the details, we are seeing issues which we can reproduce by adding the same registry to StructureMap twice. Our assumption is that our application is doing the same, perhaps adding one instance as part of a scan and a second as an explicit registration. How can I determine if

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

岁酱吖の 提交于 2019-12-06 12:33:40
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? StructureMapConfiguration.ForRequestedType<IConsumer>().AddConcreteType<Consumer>(); This method will add the Consumer

Releasing ObjectContext while using StructureMap

蓝咒 提交于 2019-12-06 12:10:21
I've been using StructureMap to inject ObjectContext (entities) into my repositories along with lazy-loaded POCO classes. This is my Structuremap registration. For<WebEntities>().LifecycleIs(new HybridLifecycle()).Use(()=>new WebEntities()); I have defined Partial classes against my POCO classes to retrieve info that is not defined in my EDMX schema. e.g. Community.FloorPlanImages would be a getter which filters only the floor plan images from all available Images. Worked pretty well until I started to optimize my queries. Using EFProf, I found out that none of my connections were being closed

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

人盡茶涼 提交于 2019-12-06 11:43:52
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. That means I'm probably stuck with the Service Locator Pattern , property injection, or writing my own

Need complete DI sample for WCF

无人久伴 提交于 2019-12-06 11:02:32
Does anyone have a complete and working DI sample for WCF? Every sample I find just gets me more confused. Does anyone know of a complete and working standalone simple sample that works with the built in stuff? Maybe once I get a handle of the built in stuff, I can move on to different DI frameworks such as StructureMap or Unity with WCF. My MVC project is currently using Unity for all its DI. Mark Seemann The code download for my book Dependency Injection in .NET contains a full, working example. However, most of what you'll need to know is explained in this answer: Injecting data to a WCF

Using WebApi and structure map dependency injection

≯℡__Kan透↙ 提交于 2019-12-06 08:48:46
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 but dependency injection is not working with WebApi controller, although if i don't use dependency

Rhino.Security and IEntityInformationExtractor

强颜欢笑 提交于 2019-12-06 08:00:45
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<IPermissionsService>() .To<PermissionsService>() .InSingletonScope(); Bind<IAuthorizationService>() .To

Structuremap - how can I get a named instance and pass parameter at runtime?

痞子三分冷 提交于 2019-12-06 06:07:26
问题 I can add a named instance to structuremap like this: For<IFoo>().Add<Foo>().Named("FooOne"); which I can then get with: ObjectFactory.GetNamedInstance<IFoo>("FooOne"); and I can pass parameters at runtime by registering like this: For<IFoo>().Add<Foo>().Ctor<string>("someParam"); and get an instance like this: ObjectFactory.With("someParam").EqualTo("blah").GetInstance<IFoo>(); All fine. But I want to have a named instance and pass it a parameter. So I'm registering like this: For<IFoo>()

Is having a wrapper for your IoC a good idea?

≡放荡痞女 提交于 2019-12-06 05:19:05
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.GetInstance(type); } public static void Inject<T>(T obj) { ObjectFactory.Inject(obj); } } I added the wrapper

StructureMap - Override constructor arguments for a named instance

我是研究僧i 提交于 2019-12-06 03:48:22
问题 Can you override the constructor arguments for a named instance, it seems you can only do it for a default instance. I would like to do: ObjectFactory.With("name").EqualTo("Matt").GetNamedInstance<IActivity>("soccer"); 回答1: GetInstance behaves like GetNamedInstance when used after .With using NUnit.Framework; using NUnit.Framework.SyntaxHelpers; using StructureMap; namespace StructureMapWith { [TestFixture] public class Class1 { public interface IFooParent { IFoo Foo { get; set; } } public