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...
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...
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...
// 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...
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()
{
...
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...
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:
...
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...
Are there equivalent for StructureMap of this in Unity:
ServiceLocator.Current.GetAllInstances<IT>
Trying to follow this little pattern...
...
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...
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...
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...
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...
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().
...
When using the fabulously useful auto-registration functionality exhibited by StructureMap; is it possible to apply scoping rules to the registered services?
...
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...
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 ...
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...
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...
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
...