structuremap

ServiceHostFactory using Structuremap that relies on HttpContext

I have an existing Structuremap ApplicationRegistry that relies on HttpContext.Current.Server and also HttpContext.Current.Items (via HttpContextScoped). I'd like to use this in my WCF ServiceHostFactory, but HttpContext.Current remains belligerently null. I am using basicHttpBinding and for the scope of the project I'm working on I'm h...

Structuremap error when using HttpContextBase in constructor

I am building a ASP.NET MVC 2.0 app on .NET 4.0 and am using Structuremap 2.6.1 for IoC. I recently added a ICookie and Cookie class, the Cookie class takes HttpContextBase as a constructor parameter (See below) and now when I run my app I get this error :No Default Instance defined for PluginFamily System.Web.HttpContextBase. I have us...

How can StructureMap be used to create setter dependencies of objects that have primitive constructor argumeents?

I have an object "TestProperty" which implements "ITestProperty". "TestProperty" takes a string constructor argument. This is configured in StructureMap using something along the lines CtorDependency or WithCtorArg. I want to inject the an instance of "ITestProperty" (implemented with "TestProperty") into another class as a property. Wh...

StructureMap IOC named instances help.

Hi, Having a problem with StructureMap IOC. I wish to retrieve different concrete implementations of objects that implement the same interface based on labels or names. internal static class InstanceHelper { internal enum Taxonomy { Foo, Bar } static InstanceHelper() { // Initialize th...

StructureMap 2.5 registry syntax

I'm trying to configure alternate constructor arguments when a requested type is being injected into several classes. In previous StructureMap versions, it would look a lot like the very first DSL example on the document page, but I'm having trouble figuring out how to configure it with the new syntax. What I've got now is an one inte...

Bestpractices: StructureMap and ASP.NET MVC 2 - Setter Injection/Contructur Injection in an abstract base Controller

public abstract class ConventionController : Controller { public const int PageSize = 5; public IMappingService MappingService { get; set;} } How do I set up StructureMap to get the Instance of IMappingService? Edit: With the help of Joshua Flanagan I now have the following code: EmployeeController public class EmployeeCon...

Is it necessary to dispose StructureMap "per request" instances?

I'm adapting some code originally written for Windsor to use StructureMap. In the Windsor example we release the handler. Is it necessary to do this with StructureMap instances that are cached "per request"? The code is: foreach (var handler in ObjectFactory.GetAllInstances<IHandle<TEvent>>()) { handler.Handle(@event...

How do I use StructureMap with generic unclosed types using Scan with a "greedy" constructor

Between various Stack Overflow questions and blog posts there is a pretty reasonable amount of documentation on the topic of open generics and StructureMap. Unfortunately, I must be missing something as my attempts at using scan to perform the configuration along with a class implementation that has a "greedy" constructor have yet work. ...

StructureMap 2.6 - How to do this in configuration file

Hi, Here is the c# code: var server = ******* some internal logic to determine server name **** var username = ******* some internal logic to determine user name **** var password = ******* some internal logic to determine password **** ObjectFactory.Initialize(x => { x.For<IService<bool>>(...

How can i initialize some Dependency Injected instance?

Hi folks, I'm using StructureMap DI/IoC and I've got is a generic InMemory repository. Works great. I was wondering if it's possible to define the initial data which each repository holds, when it's requested? Now, the first reaction is to do this in the constructor of the class - but I'm using a Generic Repository .. so i don't know w...

Setting up Fluent NHibernate and StructureMap for a web application

I use this approuch http://www.kevinwilliampang.com/2010/04/06/setting-up-asp-net-mvc-with-fluent-nhibernate-and-structuremap/ for setting up fnh with structuremap but after one request I get the following exception Session is closed! Object name: 'ISession'. Description: An unhandled exception occurred during the execution of the curr...

What is a good pattern for multi-threading in an IOC application (windsor)

I'm writing a simple photo downloader application using IOC. There is a fairly straightforward list of steps. Get list of photos to download. Check this, Check that, then download. The download can be accomplished via FTP in some cases, and via http in others, and via a web service in others. What I'm wondering, as I'm new to IOC ...

StructureMap default instance overloading with explicit arguments, error 205

I have a class: public class SystemQuery<T> : ISystemQuery<T> where T : class, IUIView { protected ISession session; protected ICriteria baseCriteria; public SystemQuery(SessionContext sessionContext) { this.session = sessionContext.Session; this.baseCriteria = session.CreateCriteria<T>(); } publi...

Property Injection into an Action Filter

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 MarketS...

How to set a default constructor argument to null with StructureMap?

A class has a unique constructor taking IMyInterface as its argument. If I define a concrete type of IMyInterface and registers it to StructureMap then there is no issue and my class can be instanciated with this concrete type. However, in some cases, no concrete type will be registered. In that case, I would like to receive null for th...

Problem Implementing Simple StructureMap Config

Hello Everyone, I just started digging into StructureMap and am running into some problems getting my config up-and-running. It seems that when I try to register Plugins in their respective PluginFamily they aren't being found by StructureMap. I've gone over many examples on the web but can't seem to see where I am going wrong. Can ...

Structure map with a ASP.Net webservice

All our apps have been converted to use strucutre map, and our libraries were converted also. I'm trying to convert one of our asp.net webservices. If I understand, correctly, I'll have to bootstrap the structuremap stuff in the constructor of the web service. But the constructor gets called with each web method called, so Each reque...

Default Constructors in Structure Map

I have this code for on ASP.NET MVC website: x.For<AccountController>().TheDefault.Is.ConstructedBy(() => new AccountController()); This code throws a warning which seems quite self explanatory but for some reason when I use the "Use" method it doesn't seem to work. I know I am doing something wrong and would appreciate some help. Th...

StructureMap strongly-typed constructor arguments

I have a bit of StructureMap config like so: x.ForConcreteType<OrderProcessor>().Configure .Ctor<string>("param1").EqualToAppSetting("setting1") .Ctor<string>("param2").EqualToAppSetting("setting2") .Ctor<string>("param3").EqualToAppSetting("setting3"); This works, but it is a bit of a magic-string approach. If I add or re...

MVC 2.0 - different view based on URL with shared controls

I have 2 master pages. One is intended to be shown in a normal standalone website. The other is to be used in external sites as an Iframe. I want to be able to show the normal page at http://example.com/home/index and the iframed version at http://example.com/framed/home/index I want to have controls that will postback to one control...