structuremap

StructureMap CacheBy InstanceScope.HttpSession not working

断了今生、忘了曾经 提交于 2019-12-01 13:23:17
问题 This is my StructureMap bootstrapping: ObjectFactory.Initialize(factory => { //Business Conversation is per session factory.ForRequestedType<IConversation>(). TheDefaultIsConcreteType<Conversation>(). CacheBy(InstanceScope.HttpSession); //Session Factory is life time factory.ForRequestedType<INHibernateSessionManager>(). TheDefaultIsConcreteType<NHibernateSessionManager>(). CacheBy(InstanceScope.Singleton); }); var conversation = ObjectFactory.GetInstance<IConversation>(); When I have my

StructureMap Conditional use

試著忘記壹切 提交于 2019-12-01 08:51:23
I hawe all day strugle my head and i canot find any solution to my case so i nead help. Hear is my problem: I hawe two classes that implement one interface public interface ICacheObject { string Get(); } public class WebCacheObject : ICacheObject { public string Get() { return "Web"; } } public class SysteCacheObject : ICacheObject { public string Get() { return "System"; } } So in some other clase For Example in Class Test I nead to inject the WebCacheObject and in Test2 clase i nead to inject SystemCacheObject. I did this in Initialize: ObjectFactory.Initialize(c =>{ c.For<IMessage>().Use

Setting up DependancyResolver in MVC3 using StructureMap for ModelMetadataProvider & ModelValidatorProvider

寵の児 提交于 2019-12-01 06:54:48
问题 Is it even possible to setup MVC3 to use the DependencyResolver in order to get a custom ModelMetadataProvider or ModelValidatorProvider? Cause at this point I can't get it to work what so ever via the DependencyResolver. If I set it explicitly via code in the global.asax it works perfectly, but IoC just silently ignores my code. I'm using the StructureMap package from NuGet so it's nothing fancy. My current hookups via global.asax Global.asax.cs ModelMetadataProviders.Current = new

StructureMap Conditional use

我的未来我决定 提交于 2019-12-01 06:47:35
问题 I hawe all day strugle my head and i canot find any solution to my case so i nead help. Hear is my problem: I hawe two classes that implement one interface public interface ICacheObject { string Get(); } public class WebCacheObject : ICacheObject { public string Get() { return "Web"; } } public class SysteCacheObject : ICacheObject { public string Get() { return "System"; } } So in some other clase For Example in Class Test I nead to inject the WebCacheObject and in Test2 clase i nead to

StructureMap MVC 5 html.Action Issue

故事扮演 提交于 2019-12-01 06:27:59
I am trying to call an Action from my view using @Html.Action("ActionName","controllerName") . But my page fails to load with below error: A single instance of controller 'Web.Areas.Area1.Controllers.ActionController' cannot be used to handle multiple requests. If a custom controller factory is in use, make sure that it creates a new instance of the controller for each request. I am using structure map for Dependency injection. Please help me what am i missing. You need to add x.For<{Your controller name}>().AlwaysUnique(); in IoC.cs file. This should be done for every controller in your

IOC DI Multi-Threaded Lifecycle Scoping in Background Tasks

荒凉一梦 提交于 2019-12-01 05:26:45
I have a application that uses IOC and DI to create and inject services. I have a service layer that handles some business logic, in the service layer I have a repository that communicates with the database. That repository is using a DataContext which is not thread safe. I want to run some functions on the service asynchronously using background tasks but know that this will cause issues with the repository. Thus I want the repository to be created for every background thread created. How is this achieved? I'm using StructureMap as the IoC. public class Service : IService { IRepository

Structuremap Disposing of DataContext object

自闭症网瘾萝莉.ら 提交于 2019-12-01 03:59:53
I wanted to be sure if structuremap will dispose my DataContext after per request ends. Here is my setup ForRequestedType<MyDataContext>().TheDefault.Is.OfConcreteType<MyDataContext>(); SelectConstructor<MyDataContext>(() => new MyDataContext()); Will structuremap auto dispose my datacontext or do i need to call Dispose manually?? No it will not Dispose it automatically, unless you use nested containers and Dispose the container holding the context instance. It's up to the creator of the context to Dispose it. The creator would usually be the part of your code calling ObjectContext.GetInstance

StructureMap MVC 5 html.Action Issue

旧街凉风 提交于 2019-12-01 03:56:52
问题 I am trying to call an Action from my view using @Html.Action("ActionName","controllerName") . But my page fails to load with below error: A single instance of controller 'Web.Areas.Area1.Controllers.ActionController' cannot be used to handle multiple requests. If a custom controller factory is in use, make sure that it creates a new instance of the controller for each request. I am using structure map for Dependency injection. Please help me what am i missing. 回答1: You need to add x.For<

Does Structuremap support Lazy out of the box?

好久不见. 提交于 2019-12-01 03:20:18
Does structuremap allow you to do constructor injection in a lazy fashion? Meaning not creating the object which is injected until it is used? UPDATE: StructureMap v3 implements this out of the box, so this trick is no longer necessary. StructureMap version 2 doesn't, but with a few tricks you can get it to do what I believe you are looking for. First of all, you can already wire up Lazy<T> instances manually like this: container = new Container(x => { x.Scan(y => { y.TheCallingAssembly(); y.WithDefaultConventions(); }); x.For<Lazy<IFoo>>().Use(y => new Lazy<IFoo>(y.GetInstance<Foo>)); x.For

IOC DI Multi-Threaded Lifecycle Scoping in Background Tasks

会有一股神秘感。 提交于 2019-12-01 03:13:09
问题 I have a application that uses IOC and DI to create and inject services. I have a service layer that handles some business logic, in the service layer I have a repository that communicates with the database. That repository is using a DataContext which is not thread safe. I want to run some functions on the service asynchronously using background tasks but know that this will cause issues with the repository. Thus I want the repository to be created for every background thread created. How is