structuremap

Managing RavenDB IDocumentSession lifecycles with StructureMap for NServiceBus and MVC

拈花ヽ惹草 提交于 2019-12-22 06:49:28
问题 I am using NServiceBus v4.3, MVC4, RavenDB 2.5 and StructureMap 2.6.4 in our solution. I am having a similar issue under StructureMap to that described in this question's responses where I require different lifecycles for the MVC Controller and NServiceBus Handler use of RavenDB's IDocumentSession in my Web project. Specifically in my case what happens is that if I use the HybridHttpOrThreadLocalScoped (as the above answer suggests for Windsor) lifecycle the sessions are not properly disposed

Property Injection into an Action Filter

﹥>﹥吖頭↗ 提交于 2019-12-22 06:27:34
问题 I'm trying to get Property Injection working on a Custom Action Filter Attribute. It is working as it is supposed to, however, I'd like to use DI on the Property itself. My filter looks like this [AttributeUsage(AttributeTargets.Class)] public sealed class HeaderFilterAttribute : ActionFilterAttribute { public IMarketService MarketService { get; set; } public override void OnActionExecuted(ActionExecutedContext filterContext) { var view = (ViewResultBase)filterContext.Result; if (view != null

Structure Map - I dont want to use the greediest constructor!

£可爱£侵袭症+ 提交于 2019-12-22 04:43:08
问题 I am trying to configure the NCommon NHRepository in my project with Structure Map. How do I stop it from choosing the greediest constructor? public class NHRepository<TEntity> : RepositoryBase<TEntity> { public NHRepository () {} public NHRepository(ISession session) { _privateSession = session; } ... } My structure map configuration ForRequestedType(typeof (IRepository<>)) .TheDefaultIsConcreteType(typeof(NHRepository<>)) Cheers Jake 回答1: You can set the [DefaultConstructor] Attribute for

Structure Map - I dont want to use the greediest constructor!

我们两清 提交于 2019-12-22 04:43:06
问题 I am trying to configure the NCommon NHRepository in my project with Structure Map. How do I stop it from choosing the greediest constructor? public class NHRepository<TEntity> : RepositoryBase<TEntity> { public NHRepository () {} public NHRepository(ISession session) { _privateSession = session; } ... } My structure map configuration ForRequestedType(typeof (IRepository<>)) .TheDefaultIsConcreteType(typeof(NHRepository<>)) Cheers Jake 回答1: You can set the [DefaultConstructor] Attribute for

what is the best practice to set up DbContext in StructureMap for console app?

送分小仙女□ 提交于 2019-12-22 01:40:21
问题 I use StructureMap, EF 4.1/POCO. Console app supposes to run 2 consequent operations upon some set of data, lets say operation1 and operation2. I set DbContext up as an singleton. This causes problem in operation2 as operation1 left some trash in its DbContext that prevent operation2 works well. In the same time I can not set up DbContext as 'per call' coz operation1 uses 2 repositories sharing the same DbContext passing through their constructor. So ideally I need reinitialize/reset/cleanup

First try StructureMap and MVC3 via NuGet

断了今生、忘了曾经 提交于 2019-12-21 14:36:13
问题 I'm trying to figure how to config StructureMap for ASP.NET MVC3 I've already using NuGet and I notice that it creates App_Start Folder with a cs file named as StructuremapMVC, so I check it and notice that is the same code but simplified that will be written manually on App_Start section placed on Global.asax... This is my code from IoC Class public static class IoC { public static IContainer Initialize() { ObjectFactory.Initialize(x => { x.Scan(scan => { scan.TheCallingAssembly(); scan

Structuremap in Singleton returning multiple instances

ぃ、小莉子 提交于 2019-12-21 13:02:30
问题 I have registered 5 derived classes for the same interface using named instances. All these classes are registered as Singleton For<IBaseInterface>().Singleton().Use<DerivedClass1>().Named("Derived1"); For<IBaseInterface>().Singleton().Use<DerivedClass2>().Named("Derived2"); For<IBaseInterface>().Singleton().Use<DerivedClass3>().Named("Derived3"); There is a static class which resolves the instance based on input. However I observed that every call to ObjectFactory.GetInstance returns new

Issues Configuring StructureMap.MVC5 to work with Identity

折月煮酒 提交于 2019-12-21 05:42:09
问题 I am currently trying to reconfigure StructureMap in our application after upgrading from an old version (2.6) that was never correctly implemented in the first place. I am new to using DI Containers to begin with, and am finding documentation for newer StructureMap versions hard to find. I uninstalled the old 2.6 version of StructureMap and installed StructureMap.MVC5 (since I am using MVC5). What I am having issues with is the AccountController. I have StructureMap set up to use the

How to release HybridHttpOrThreadLocalScoped objects in StructureMap?

二次信任 提交于 2019-12-21 04:04:48
问题 When performing background tasks in a Windows Service I used HybridHttpOrThreadLocalScoped for storing intances of NHibernate ISessions. Since within a Windows Server there isn't a HTTPContext, I'm wondering if only calling the ReleaseAndDisposeAllHttpScopedObjects() is enough to release the ISession instance for that thread? 回答1: I found out how to answer this question. The ReleaseAndDisposeAllHttpScopedObjects() method exposed by the ObjectFactory is really concerned with the HttpContext

StructureMap and the decorator pattern

爱⌒轻易说出口 提交于 2019-12-21 03:33:15
问题 I'm using StructureMap, v. 2.5.3 and am having trouble with chaining together implementations on an interface to implement the Decorator pattern. I'm used to Windsor, where it is possible to name variations on interface implementations and send the named impl. into another (default) impl. This is the default, non decorated version, which works fine: ObjectFactory.Initialize(registry => { registry.ForRequestedType<ICommentService() .TheDefault.Is.OfConcreteType<CommentService>(); ... } This is