dependency-injection

How to perform conditional binding in StructureMap from within a registry and without the use of generics?

I am familiar with Ninject and in Ninject you can do something similar to Bind<ICalendar>().To<MonthCalendar>().WhenInjectedInto(typeof(Roster)).InRequestScope(); I'm not sure how to perform something similar in StructureMap. I need to be able to do this dynamically from my own binding without the use of the generic StructureMap metho...

structuremap Property Injection

How to do Dependency Injection on Property of a class Using Structure Map public class ContactController : Controller { public IContactService Service { get; set; } public ContactController() : this(null,null) { } [SetterProperty] public MembershipProvider Provider { get; private set; } } Here when i ...

Seam Session scoped component vanishes in next request.

I have the Seam session-scoped component, CustomIdentity which overrides the standard Seam Identity (also session-scoped). The extended CustomIdentity has a property @Out(required=false, scope=ScopeType.SESSION)private User user In the overriden login() I define a User object, populated with information from the Principal of the Http...

In Autofac how do I change the instance that is registered after Build has been called?

So lets say i have this code var builder = new ContainerBuilder(); builder.RegisterInstance(new MyType()); var container = builder.Build(); Then some time later I want to change the instance of MyType for all future resolves that are called on container. ...

WPF Prism Inject same viewmodel instance into two views

So I have two separate views in a WPF Prism app. How can I inject the same instance of a viewmodel into both the views via Depencency Injection? ...

Ninject binds to the wrong anonymous method when there is more than one method bound type

I am building a framework that I don't want to couple to a particular IOC container so have created a layer on top of Ninject / structuremap etc. I have a binding class that accepts a Func to allow binding to a method. For example public class Binding { public Type Source { get; set; } public Func<object> Method {get; set; } public...

Recommended books on CDI (JSR299)

Hi all, I was wondering if there is already a book available, more or less dedicated to CDI (Contexts and dependency injection - JSR299). Dependency Injection by Dhanji Prasanna is a good book, but it more focussed on JSR330 and Spring DI. Thank you, J. ...

Dependency resolution as a seperate project ..How to?

hi, I am creating a new application using asp.net mvc, I m using munq IOC container as my dependency injection..The issue is i want to create a new project for dependency resolution where i can register all the controllers of mvc project and the repositories of infrastructure project..I have to add Dependency Resolution project as a refe...

Dependency injection in the .net world without needing XML config files

Dependency injection looks great, however when I look at examples I often see lots of XML config file. This is not good because: I don’t get compile time checking on the type names in the config files Refactoring tools don’t update the confilg files when types are renamed I don’t want the customers changing the configuration! I am a ...

Setter injection on an existing service instance in Castle Windsor

Does Castle Windsor support applying setter injection to existing service instances? I have a case in which I have no control over the creation of certain class instances while I do need to resolve dependencies for them. This rules out constructor injection but leaves the door open for setter injection since I can intercept the new insta...

MVVM-PRISM, how to display multiple instances of a view in a region/ItemsControl

Hi! I am building an module for an application that is based on MVVM, CAL and PRISM. I'm fairly new to these concepts, and trying to get my head around all the patterns and right now I'm struggling with the following problem: I am in the need of creating multiple instances of the same View. Each one of the views need to bind to it's o...

Using dependency property in WPF

I have a readonly .NET property exposed from a managed wrapper which gets the name of the database, let's say the property name is DBName. The DBName may vary depending upon the database connected to the WPF application. This property getter and setter also resides inside the managed .NET wrapper. I am using this(DBName) property in my...

Problem instantiating generic class bean in Spring

Hi, I'm trying to instantiate a generic class in Spring, but I get following exception: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class football.dao.jpa.GenericJpaDAO]: Common causes of this problem include using a final cla...

When to and When not to use IOC/Dependency Injection?

I am working with several Spring MVC web applications and I use the getter/setter dependency injection and configure all my beans in my app-servlet.xml file. I believe that I am following convention with most of the properties and beans that I am injecting into my controller beans such as my DAO's and other beans that I have specified i...

Dependency Injection Frameworks: How do they work?

I consider myself an experienced programmer and understand the basic concept of dependency injection. On the other hand, most of my experience is in writing relatively low-level, one-man number crunching code. I have no experience whatsoever working on large enterprise projects. Given this background, I can't for the life of me wrap m...

Get parent bean in prototype bean that gets injected

Hi, I would like to have a Bean and a SubBean like this: @Scope(BeanDefinition.SCOPE_PROTOTYPE) @Component public class SubBean implements ApplicationContextAware{ private Object parent; public void setApplicationContext(ApplicationContext ctx){ this.parent = doSomeMagicToGetMyParent(ctx); } public Object getParent(){ ...

dependency injection with asp.net mvc

I have a service class : public class MyService : IService { private IRepoA repoA; private IRepoB repoB; public MyService(IRepoA repoA,IRepoB repoB) { this.repoA=repoA; this.repoB=repoB; } } my Controller depends on the MyService classL public MyController : DefaultController { IService myServ...

How to reuse a transient dependency in same context with Castle Windsor DI container

If I have the following setup, how can I configure my container to use the same database, when objects are created in the same context public class Database { } public interface IRepository { Database Database { get; } } public interface IFooRepository : IRepository { } public interface IBarRepository : IRepository { } public class Foo...

How to avoid having injector.createInstance() all over the place when using guice?

There's something I just don't get about guice: According to what I've read so far, I'm supposed to use the Injector only in my bootstrapping class (in a standalone application this would typically be in the main() method), like in the example below (taken from the guice documentation): public static void main(String[] args) { /* ...

Ninject inject add an element to collection when I create the collection

I'm using MVVM light and have set up the binding as following: class TestModule:NinjectModule { public override void Load() { Bind<ICollection<Element>>().To<Collection<Element>>(); Bind<Element>().ToSelf(); } } When I try to get a ICollection I get a collection with ONE element. I expect an exmpty collecti...