structuremap

Reset ObjectFactory in StructureMap

♀尐吖头ヾ 提交于 2019-12-11 05:56:07
问题 I'm writing some unit tests that rely on StructureMap so I want to completely reset the ObjectFactory in my [SetUp] method. This is what my [SetUp] method looks like right now: [SetUp] public void SetUp() { ObjectFactory.Initialize(initializationExpression => {}); } This appears to reset the configuration because I can execute the ObjectFactory.WhatDoIHave() method and it does not contain any of my configuration. However, cached instances of objects are not removed and are returned in

StructureMap configuration for DI with asp.net MVC / Linq2Sql combo?

送分小仙女□ 提交于 2019-12-11 04:18:16
问题 Here is my incomplete StructureMap configuration: PS: Big apologies for asking you to write my app for me but I'm finding the StructureMap api to be a bit confusing as nearly everything I find when I do google searches refers to the older api. public static void Configure(IContainer container) { container.Configure(c => { string connectionString = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString; SQLDataContext dataContext = new SQLDataContext(connectionString); c.For

How to manage interface segregation when using an IoC container? [duplicate]

夙愿已清 提交于 2019-12-11 03:59:46
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: StructureMap singleton usage (A class implementing two interface) I'm currently designing a small system and i'm currently using structureMap as IoC. I just recently got the point of interface segregation...and I'm wondering now. If I have a certain business object, that will implement say, three interfaces... how should I handle this in the configuration and instatiation of code? Assuming I have two interfaces

How to set up Redis in custom namespace as cache and MQ on ServiceStack web application using Structuremap

房东的猫 提交于 2019-12-11 02:12:19
问题 I want to set up my application to use Redis as Cache for sessions etc as well as run my Message Queues. My application is a ASP.net MVC website along with ServiceStack based Json service provider. What is the optimal way to configure? I want to be able to pass an IMessageQueueClient into my service classes and controllers so that I can add tasks to the queue. I'm getting somewhat lost over what scope to make what. My code is as follows: //Redis Client Manager var pooledClientManager = new

What's the difference between these two StructureMap configs?

坚强是说给别人听的谎言 提交于 2019-12-11 02:00:42
问题 We're struggling with understanding the difference between these two ways to configure StructureMap. Our understanding is that they should be identical but we get different results between these two lines inside of Initialize: ObjectFactory.Initialize(x => { x.For<IBusinessRelationsContext>().Use<BusinessRelationsContext>().Ctor<string>().Is(ConfigurationManager.ConnectionStrings["BusinessRelationsContext"].ConnectionString); x.For<IBusinessRelationsContext>().Use(_ => new

StructureMap and Nested Generics

寵の児 提交于 2019-12-11 01:48:28
问题 I am wondering if there is a way to wire up nested generics within StructureMap without having to specify the internal type or create type specific interfaces. I realize that this is a bit confusing, so a coding example might be a better explanation of the functionality that I am looking for. public interface IParser<T> { } public class Range<T> where T : struct { } public class RangeParser<T> : IParser<Range<T>> { } Theoretically, I would like to be able to follow StructureMap's open generic

Intermittent “Specified cast is invalid” with StructureMap injected data context

北慕城南 提交于 2019-12-11 01:27:06
问题 I am intermittently getting an System.InvalidCastException: Specified cast is not valid. error in my repository layer when performing an abstracted SELECT query mapped with LINQ. The error can't be caused by a mismatched database schema since it works intermittently and it's on my local dev machine. Could it be because StructureMap is caching the data context between page requests? If so, how do I tell StructureMap v2.6.1 to inject a new data context argument into my repository for each

StructureMap and HTTP request-scoped services - why is my service created twice in a single scope?

不羁岁月 提交于 2019-12-10 22:46:34
问题 I have an ASP.NET MVC application using StructureMap. I have created a service called SecurityContext which has a static Current property. A simplified version looks like this: public class SecurityContext : ISecurityContext { public bool MyProperty { get; private set; } public static SecurityContext Current { get { return new SecurityContext() { MyProperty = true }; } } } I've hooked this up in my StructureMap registry as follows: For<ISecurityContext>().Use(() => SecurityContext.Current);

Setting ASP.NET MVC ControllerFactory has no effect

喜欢而已 提交于 2019-12-10 21:55:10
问题 I'm trying to have my ASP.NET MVC2 controllers built using StructureMap but ASP.NET doesn't seem to remember that I've called ControllerBuilder.Current.SetControllerFactory in my Global.asax file. Specifically I get the error that my controller has no parameterless constructor. The stack trace reveals that my custom ControllerFactory was never actually executed. Here is my call to the method that should tell ASP.NET which ControllerFactory to use: Sub Application_Start() RegisterRoutes

Define filter for DecorateAllWith() method in structure-map 3

纵然是瞬间 提交于 2019-12-10 17:36:12
问题 I used following statement to decorate all my ICommandHandlers<> with Decorator1<> : ObjectFactory.Configure(x => { x.For(typeof(ICommandHandler<>)).DecorateAllWith(typeof(Decorator1<>)); }); But because Decorator1<> implements ICommandHandlers<> , the Decorator1<> class decorates itself too. So, the problem is that the Decorator1 registers inadvertently, when I register all the ICommandHandler<> 's. How can I filter DecorateWithAll() to decorate all ICommandHandler<> , except Decorator1<> ?