structuremap

How to scan and auto-configure profiles in AutoMapper?

Is there any way to auto-configue Automapper to scan for all profiles in namespace/assembly? What I would like to do is to add mapping profiles to AutoMapper from given assembly filtered by given interface, something like Scan Conventions in StructureMap: public static void Configure() { ObjectFactory.Initialize(x => ...

When using Dependency Injection with StructureMap how do I chooose among multiple constructors?

I'm trying to get structuremap to build Fluent Nhibernate's SessionSource object for some of my intregration tests. The only problem is that Fluent's concrete implementation of ISessionSource (SessionSource) has 3 constructors: public SessionSource(PersistenceModel model) { Initialize(new Configuration().Configure(), m...

structuremap configuration change based on settings in app.config

I am using structuremap in my project. To inject different implementation of a repository, I want to have a switch in app.config which changes all real implementation of a repository to a mock repositories. Lets say IRepository has two implementations RealRepository and MockRepository ForRequestedType() .TheDefaultIsCon...

Wanna use StructureMap to store HttpContext/User based explicit instances

Hi I'm having difficulty figuring out how to store an explicitly user generated instance in StructureMap, cached by HttpContext. When I try the code underneath, I even get the first cached instance, which leads to failures when using it for storing user credentials in Asp.Net AuthenticateRequest method. ForRequestedType<TInterface>() ...

Get instance of type inheriting from base class, implementing interface, using StructureMap

Continuing on my quest for a good plugin implementation I have been testing the StructureMap assembly scanning features. All plugins will inherit from abstract class PluginBase. This will provide access to common application services such as logging. Depending on it's function, each plugin may then implement additional interfaces, for e...

Injecting An Instance Into StructurMap After Bootstrapping HttpContext Scoped

I'm trying to use StructureMap in an asp.net MVC application instead of using HttpSession to store instances. My simple test class: public interface ICurrentSession { User User { get; set; } } public class CurrentSession : ICurrentSession { public User User { get; set; } } Here is the relevant registry code which is called in ...

More control over instantiation of generic types?

Hello, I am trying to use StructureMap to register some types that implement a generic interface and are instantiated via a factory. My code: public interface IManagerBase<T, TKey> : IDisposable { // Get Methods T GetById(TKey Id); } public partial interface IServerHostManager : IManagerBase<ServerHost...

Creating A Single Generic Handler For Agatha?

I'm using the Agatha request/response library (and StructureMap, as utilized by Agatha 1.0.5.0) for a service layer that I'm prototyping, and one thing I've noticed is the large number of handlers that need to be created. It generally makes sense that any request/response type pair would need their own handler. However, as this scales ...

Injecting multi-tenant repositories with StructureMap in ASP.NET MVC

I'm implementing StructureMap in a multi-tenant ASP.NET MVC application to inject instances of my tenant repositories that retrieve data based on an ITenantContext interface. The Tenant in question is determined from RouteData in a base controller's OnActionExecuting. How do I tell StructureMap to construct TenantContext(tenantID); wher...

StructureMap problems with bidirectional/circular dependencies

I am currently integrating StructureMap within our business layer but have problems because of bidirectional dependencies. The layer contains multiple manager where each manager can call methods on each other, there are no restrictions or rules for communication. This also includes possible circular dependencies like in the example belo...

Define Default constructor Structuremap in a Generic Repository

Hello guys, I have a generic IRepository that has 2 constructors, one have none parameters, other has the datacontext as parameter. I want to define to structuremap to aways in this case use the parameterless constructor. I want a way to create a parameterless contructor, other solutions that I have seen, they create a new Datacontext a...

.NET - create instance of each type that implements specific interface

Hi. I have interface IModule and several classes that implements it. In test i need to create instance of each type(class) implementing that interface. Is is possible(with StructureMap)? ...

StructureMap IoC problem getting the instance in runtime

i have 2 concrete types "CategoryFilter" & "StopWordsFilter" that implements "IWordTokensFilter". Below is my setup: ForRequestedType<IWordTokensFilter>().TheDefaultIsConcreteType<CategoryFilter>() .AddInstances(x => { x.OfConcreteType<StopWordsFilter>(); } ); The problem is...

Circular dependencies in StructureMap - can they be broken with property injection?

Hi, I've got the simplest kind of circular dependency in structuremap - class A relies on class B in its constructor, and class B relies on class A in its constructor. To break the dependency, I made class B take class A as a property, rather than a constructor argument, but structuremap still complains. I've seen circular dependencies ...

Converting From Castle Windsor To StructureMap In An MVC2 Project

I am learning about best practices in MVC2 and I am knocking off a copy of the "Who Can Help Me" project (http://whocanhelpme.codeplex.com/) off Codeplex. In it, they use Castle Windsor for their DI container. One "learning" task I am trying to do is convert this subsystem in this project to use StructureMap. Basically, at Application_...

StructureMap with Interception and Castle.DynamicProxy

Hi. I'm trying to get StructureMap to put a Castle.DynamicProxy around some of the objects it creates. I have used the EnrichWith-feature earlier, but I think RegisterInterception would suit me better in this case, since I use scanning. The problem is that in the "Process(object target, IContext context)"-method, I can't find out which...

ASP.NET MembershipProvider and StructureMap

I was using the default AspNetSqlMembershipProvider in my application. Authentication is performed via an AuthenticationService (since I'm also supporting other forms of membership like OpenID). My AuthenticationService takes a MembershipProvider as a constructor parameter and I am injecting the dependency using StructureMap like so: F...

Best way to mock out external web services while testing a web application in development

Currently I am working on an application which depends on a lot of external web services. A few of them are authorize.net and chargify. When testing(manual testing) things other than the integration with these web services, I replace these web service dependencies with fake versions of them which don't really do anything. The way I am...

Using StructureMap, when a default concrete type is defined in one registry, can it be redefined in another registry?

In the project I'm working on I have a StructureMap registry for the main web project and another registry for my integration tests. During some of the tests I wire up the web project's registry, so that I can get objects out of the container for testing. In one case I want to be able to replace a default concrete type from the web reg...

Passing constructor arguments when using StructureMap

Hello, I'm using StructureMap for my DI. Imagine I have a class that takes 1 argument like: public class ProductProvider : IProductProvider { public ProductProvider(string connectionString) { .... } } I need to specify the "connectionString at run-time when I get an instance of IProductProvider. I have conf...