structuremap

Injecting non-primative types without wrapping them in an inteface in StructureMap

I have a simple SM Registry where I am configuring all my instances of IDynamicValue. I have some contructor arguments that are non-primative types (in my case a DateTime and a Predicate Of T). Is there a way I can inject these without having to wrap them in a class with an interface (so they can be auto-wired). The following code snippe...

Strange behaviour with StructureMap / ASP.MVC / Visual Studio / LinqToSql

I have been using the new MVC framework with StructureMap recently and have had good results overall, however, I keep running into a very strange error that I cannot understand or work out how to resolve. This is my architecture: DBContext - linqToSql data context. IRepository - contract defining data methods. IService - contract def...

How to define a Structuremap named instance in Code

Hi, I want to create a Structuremap named instance in code, without config file I want to be able to create the instance like this: var namedInjector = ObjectFactory.GetNamedInstance<IInjectable>("Other"); I cant define such a type in code. I have found this sample but it uses the old syntax of a previous version and defines the nam...

StructureMap -> EnrichWith is enriching too much (other instances)

// Enrich with is enriching more than i want public intefrace ICommand { void Execute(); } // classes public class A : ICommand {} public class B : ICommand {} public class MultiCommand : ICommand { public MultiCommand(ICommand[] commands) {} } // -- decorators public DecoratorOne : ICommand { public DecoratorOne(Icommand toDe...

Structure map InstanceScope.Hybrid with asp.net mvc misbehaves

I'm really stuck here. I have a asp.net mvc application and use StructureMap 2.5.3 (SM) to inject service and repository classes in my controllers. All controller are made by a SM factory. I also have a Linq to SQL datacontext which I wanted to cache by hybrid. public class DBRegistry:Registry { public DBRegistry() { ...

Inject different object to constructor with StructureMap for certain case

I have IRepository<T> , and implementation SqlRepository<T>. SqlRepository has DataContext parameter in constructor. SM configuration looks like this: x.ForRequestedType(typeof(IRepository<>)) .TheDefaultIsConcreteType(typeof(SqlRepository<>)); x.ForRequestedType<DataContext>().CacheBy(InstanceScope.Hybrid) .TheDefault.Is.Constructe...

Using Ninject (or some other container) How can I find out the type that is requesting the service?

Suppose I have an interface for a service: public interface IFooService { void DoSomething(); } And a concrete implementation of that service that is a generic: public class FooService<TRequestingClass> : IFooService { public virtual void DoSomething() { } } And I have some other class that needs an instance of IFooService: ...

Custom Controller Factory, Dependency Injection / Structuremap problems with ASP.NET MVC

I recently tried to implement dependency injection using StructureMap. I managed to follow the example all the way but I'm encountering a thrown exception every time I try to run the application. Here's some code snippets from my controller factory. public class StructureMapControllerFactory : DefaultControllerFactory { protected ov...

Unity & StructureMap

Are there equivalent for StructureMap of this in Unity: ServiceLocator.Current.GetAllInstances<IT> Trying to follow this little pattern... ...

StructureMap with ASP.NET MVC - configure() method is obsolete?

I have overriden the DefaultControllerFactory by using CustomControllerFactory which is actually using StructureMAp ObjectFactory to construct the Controller Instance using IOC. But some how it can not find the Controller instances and failing over it. Note. I already set the DEfaultControllerFactory in Global.asax too. So is there anyth...

StructureMap: How do you define a default constructor for an open generic?

I have some configuration with open generics that looks like this: x.ForRequestedType(typeof(IRepository<>)) .TheDefaultIsConcreteType(typeof(MyRepository<>)); I need to tell SM that it should NOT use the greediest constructor when building my repo. How do I do this? Its easy enough when I'm using ForRequestedType<>, but it a...

Using StructureMap to cache a named instance

I'm having difficulty figuring out how to have StructureMap cache a non-default instance. I can cache the default instance with code like this ForRequestedType<ISession>() .CacheBy(InstanceScope.HttpContext) .TheDefault.Is.ConstructedBy(() => ObjectFactory.GetInstance<ISessionFactory>().OpenSession()); which w...

Structuremap 2.0 documentation

I'm just starting to learn DI/IOC methods and like what I see so far from Structuremap. The problem is that my current project is limited to .NET 2.0 so I cannot use the new version (2.5) of Structuremap. That being said, can someone point me towards some documentation for v2.0? Most articles and tutorials use v2.5 and only a small fe...

Can I replace the call to Activator.CreateInstance() in NHibernate?

Is there a way to replace the call to Activator.CreateInstance() used inside NHibernate 2.0.1GA to construct the entities? Ideally I'd like to replace it with StructureMap.ObjectFactory.GetInstance(). ...

Scanning and Scoping

When using the fabulously useful auto-registration functionality exhibited by StructureMap; is it possible to apply scoping rules to the registered services? ...

How to use cumstomized configuration xml file?

I am going to use StructureMap as a way to do DI. I'll use xml as my DI configuration. I have two questions. The first one is how to use a customaized xml file name instead of StructureMap.Config? For example, in my console application, if I want to use myDIStructure.config file, what class and method should I use in the main(): privat...

StructureMap for customized construtor

I am using StructureMap with VS 2005. I want to inject a class like this: public class MyClass : IMyInf { public MyClass(int id) {...} .... } I tried several methods such as: ForRequestedType<IMyInf>>().TheDefault.Is. OfConcreteType<MyClass>().WithProperty("id").Equals(2) I got compiling error with .Net 3.5 Linq required. Is ...

Entity Framework + POCO

I am building a WPF application using the MVVM pattern. Our stack looks like this: SQL Server 2008 -> Entity Framework We use StructureMap for dependency injection to inject our DataFactory which essentially does the CRUD for our POCO business objects. The ViewModels use the DataFactory for CRUD and the xaml is data bound to the prop...

How do you deploy an ASP.NET MVC site using StructureMap 2.5.3 in a medium trust hosting envrionment?

I am getting a SecurityException (as seen below), even with [assembly: AllowPartiallyTrustedCallers] in my AssemblyInfo.cs. I am deploying to GoDaddy, which is a medium trust environment, which I don't think StructureMap is set up to run under natively, although the 2.5.3 release notes mention adding the AllowPartiallyTrustedCallers att...

How to use StructureMap for the case of primitive types in CTOR

I have following following CTOR for a class: public class Log : ILog { ... public Log (string file, string flag) { .... } .... } I tried the following codes to make DI mapping: public MyStructureMap { public void static InitializeMapping() { StructureMap.DSL.Registiry.ForRequestedType<ILog>().TheDefault.Is ...