Questions tagged [structuremap]

StructureMap is a Dependency Injection / Inversion of Control tool for .NET licensed under Apache 2.

StructureMap is a Dependency Injection / Inversion of Control tool for .NET licensed under Apache 2. It can be found at https://structuremap.github.io/.

Installation

StructureMap can most easily be installed through its NuGet package.

Install-Package structuremap

Links

Related

1728 questions
22
votes
4 answers

SignalR + Dependency Injection Questions

I am using SignalR in my MVC3 application, and since I have implemented StructureMap Dependency Injection on my controllers I would like to do the same in my hub, but I can't seem to get it working. Please tell me what's wrong with my codes…
22
votes
2 answers

How to Mock an AutoMapper IMapper object in Web API Tests With StructureMap Dependency Injection?

So I've build a WebAPI from scratch, including some best practices that I've found online such as Dependency Injection and Domain<->DTO mapping using auto mapper etc. My API Controllers now look similar to this public MyController(IMapper…
kob490
  • 3,177
  • 4
  • 25
  • 40
22
votes
2 answers

WebAPI + APIController with structureMap

Im trying to use StructureMap to initialize my ValuesController that derivate from ApiController but i'm getting an exception that says: The IControllerFactory '...CustomControllerFactory' did not return a controller for the name 'api'. Here is the…
gds03
  • 1,349
  • 3
  • 18
  • 39
21
votes
3 answers

Using IoC in extension methods

I am working on an ASP MVC 3 app and I'm writing a custom html helper. It's nothing special or hugely complex, but it will need an instance of an interface from structure map. I know I can simply call into structuremaps' object factory from inside…
ilivewithian
  • 19,476
  • 19
  • 103
  • 165
20
votes
6 answers

Entity Framework : Change connection string at runtime

Assuming there is an ASP.NET MVC application that uses Entity Framework 6 with a code-first approach and StructureMap as IoC. It also uses the Unit Of Work pattern. Domain Class: public class Product { public int Id { get; set; } public…
Shahin
  • 12,543
  • 39
  • 127
  • 205
19
votes
2 answers

Mapper not initialized, When Use ProjectTo()

I Use Automapper 5.2.0 In My Project. When I Use ProjectTo() In Code Get This Error: Mapper not initialized. Call Initialize with Appropriate configuration. If you are trying to use mapper instances through a container or otherwise, make sure you…
Soheil Alizadeh
  • 2,936
  • 11
  • 29
  • 56
18
votes
4 answers

ASP.NET MVC: HTTPContext and Dependency Injection

Currently I have an ActionFilter that gets the current users name from HttpContext and passes it into the action which uses it on a service method. eg: Service.DoSomething(userName); I now have a reason to do this not at the action level but the…
anonymous
  • 6,825
  • 8
  • 47
  • 60
18
votes
2 answers

What is the equivalent of HybridHttpOrThreadLocalScoped in structure map 3?

With structuremap 2.6.4.1 my container is configured like this: existingContainer.Configure(expression => { expression.For() .HybridHttpOrThreadLocalScoped() .Use(container => { …
marcus
  • 9,616
  • 9
  • 58
  • 108
17
votes
4 answers

structuremap - two implementations of same interface

I have a service class with the following ctor: public class (IMessageService emailService, IMessageService smsService) { ... } and two implementations of IMessageService (email and sms). How do I configure the container to resolve this…
Myles McDonnell
  • 12,943
  • 17
  • 66
  • 116
17
votes
4 answers

How to configure StructureMap for asp.net MVC 5

I'm getting below error. I setup it similar to asp.net mvc 4. No parameterless constructor defined for this object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for…
16
votes
1 answer

Injecting a DbContext into a FluentValidation validator

I am using the FluentValidation library to enforce a unique constraint on one of my models: public class Foo { // No two Foos can have the same value for Bar public int Bar { get; set; } } public class FooValidator : AbstractValidator
16
votes
1 answer

AddAllTypesOf vs ConnectImplementationsToTypesClosing

I'm curious as to the difference between these two methods. I'm implementing a decorator pattern with open generics and whether I use AddAllTypesOf or ConnectImplementationsToTypesClosing it doesn't matter, I get the same functionality. public class…
16
votes
3 answers

How to define a default constructor by code using StructureMap?

I can't figure out how to define the default constructor (when it exists overloads) for a type in StructureMap (version 2.5) by code. I want to get an instance of a service and the container has to inject a Linq2Sql data context instance into it. I…
Cyril Bioley
  • 391
  • 1
  • 3
  • 9
16
votes
2 answers

How to configure Web API 2 and Structure Map

I've trawled through multiple blogs etc trying to find out how to configure StructureMap with Web API 2 and none of the implementations worked for me. The confusion seems to be around the different IDependency Resolver that MVC uses and the one that…
Greg
  • 2,654
  • 3
  • 36
  • 59
15
votes
2 answers

StructureMap Constructor arguments

I'm new to structureMap. How do I define constructor arguments for the following class with fluent configuration? Thanks public BlobContainer(CloudStorageAccount account , string containerName , string contentType …
Game99
  • 227
  • 3
  • 6