If I have a class like so:
public SomeClass : ISomeClass
{
public SomeClass(IInjectedDependency dependency, bool someArbitraryValue) {}
}
How can I set this up with SM to inject the dependency but specify the arbitrary value?
I've tried the following but it doesn't work (I get "There is no argument of type System.Boolean for conc...
Hi
I've got a rookie question about StructureMap.
In my app, on startup, I load a bunch of settings, in a list, from the DB, which all my threads will need to access at one time or another.
So I wonder, can I make the list a singleton and share across my injections like so:
//Class for task
public class MyTask1 : IMyTask1
{
public ...
I have a class that relies on HttpServerUtilityBase my plan was to get structure map to use HttpServerUtilityWrapper as the default instance. Nothing odd there. However, once I've added the declarations to my registry, structuremap is unable to resolve the instance and I get a 202 error.
This is my registry:
public class ApplicationReg...
If i have the following Repository:
public IQueryable<User> Users()
{
var db = new SqlDataContext();
return db.Users;
}
I understand that the connection is opened only when the query is fired:
public class ServiceLayer
{
public IRepository repo;
public ServiceLayer(IRepository injectedRepo)
{
this.repo = injec...
Hi,
I need to setup session management in MVC. what is the correct way of doing so?
How to setup nhibernate session management in mvc using structuremap so I don't get:
Session is closed
or
Using a single Session in multiple threads is likely a bug.
My current configuration is:
in GlobalAssax:
protected void Application_Start()
{
...
We have many long-running processes that each require dozens of steps. Each step is relatively complex in its own right, so we broke those steps into their own classes. We are using DI/IoC (StructureMap) to help us make the whole thing testable. This has been working great, but we find ourselves with oodles of dependencies in our cont...
Ok, I give up...
What I want is to share the EF4's DbContext instance per request. I configured StructureMap like this:
For<MyContext>().Use(new MyContext("LocalhostConnString"));
But when I refresh my site, or even open it in another browser, I get the same exact instance of MyContext. Why is this shared across requests?
Am I missi...
I'm new to structure map and so far having good luck. However, there's one area I'm having a bit of a problem with. This is trying to auto-wireup using named instances and the newer .For().Use() syntax.
No matter what I do, I'm getting the LAST item I've configured for a given type when I'm trying to auto-wire to create a new object. I...
Ok so this might not be the best title but I am struggling with how to title this. Here is what I have thus far:
I currently have data mappers for my objects. I define them in a registry like so. This allows me to get the type name of the object and combine that with the word Mapper and request it. Here is the code I am using:
this.For...
I have a piece of code that I can run in four ways
Debug build - in the debugger - works just fine
Debug build - outside debugger - fails
Release build - in the debugger - fails
Release build - outside debugger - fails.
The error code is gives in all cases is 202 - something to do with parameterless constructors, call stack at the bo...
I have an ASP MVC application using LINQ to SQL for data access.
I am trying to use the Repository and Unit of Work patterns, with a service layer consuming the repositories and unit of work.
I am experiencing a problem when attempting to perform updates on a particular repository.
My application architecture is as follows:
My service ...
I am currently making the move from StructureMap to Castle Windsor.
Using StructureMap, you can bootstrap the framework in one central location, and then call ObjectFactory.GetInstance anywhere in your code to grab an instance using that configuration. So conceptually there is a single container that you configure, and calls to the Obj...
I have the following classes:
public class AllowanceManager : IAllowanceManager
{
public AllowanceManager(ITranslationManager t_Manager, ISessionManager s_Manager)
{...}
}
public class TranslationManager : ITranslationManager
{
public TranslationManager(string culture)
{...}
}
public class SessionManager : ISessionMan...
Why should I prefer StructureMap over Unity?
...
I would like to have my own injection attribute so that I am not coupling my code to a particular IOC framework. I have a custom injection attribute that my code uses to denote that a property should be injected.
public class CustomInjectAttribute : Attribute {}
Fictitious example below...
public class Robot : IRobot
{
[CustomInje...
I'm using StructureMap for dependency injection and I want to inject NHibernate sessions with it. I have the following code:
private static Container _container { get; set; }
static MyClass()
{
_container = new Container(r =>
{
r.For<ISessionFactory>().Singleton()
.Use(NHibernate.GetSessionFactory());
...
Hi folks,
I've got a windows application that creates some threads to parse some txt files. Nothing too crazy.
I'm using StructureMap Dependency Injection to create any instances of my Services and Repositories. So my Winform has a static property which returns the instance, based on what's been registered. Works great .. except I'm n...
By my (likely meager) understanding, doing this in the middle of a method in your controller / presenter is considered bad practice, since it creates a dependency between StructureMap and your presenter:
void Override() {
ICommentForOverrideGetter comm = StructureMap.ObjectFactory.GetInstance<ICommentForOverrideGetter>();
since th...
If I have the following, and I were to say ObjectFactory.GetInstance<Master>() is it possible to tell StructureMap to make the I_A instance to A_User the same instance as the I_A passed to Master?
public interface I_A { }
public interface I_B { }
public class A_User {
public A_User(I_A A) { }
}
public class Master {
public Mas...
I have a typical repository interface, IRepository<T>, and lots of concrete repositories. Most of the concrete repositories look like this:
class ConcreteRepository<T> : IRepository<T> { .. }
These are easy to register with StructureMap:
For(typeof(IRepository<>)).Use(typeof(ConcreteRepository<>));
However, a select few of my conc...