dependency-injection

StructureMap profiles and web requests question

I want to have several different versions of my software based on a parameter passed in on the request. I'm currently trying to accomplish this with profiles. What I need to know is, if I have something like (pseudo) ObjectFactory.Profile = Request.Params["version"]; var instance = ObjectFactory.GetInstance(...); is it possible for ...

Ninject to bind on different controllers

I am trying to Bind two concrete classes to one interface. What command should I use in Ninject to do that? What I am trying to do is to Bind two concrete classes to one interface base on the controller Name. Is that possible? I suppose that in ninject you use the .When to give the conditional but there is no tutorial out there where the...

Dead Code Detector for Guice/Gin modules?

Usual dead code detectors don't seem to find which defined objects in a Guice or Gin module are not needed any more: is there a simple way to detect this? For example, let's say I defined a Provider method for a type with a certain annotation: @Provides @Named("string range") String getStringRange(Request foo) { return foo.getBarPr...

How to pass unit of work container into constructor of repository using dependency injection

I'm trying to work out how to complete my implementation of the Repository pattern in an ASP.NET web application. At the moment, I have a repository interface per domain class defining methods for e.g. loading and saving instances of that class. Each repository interface is implemented by a class which does the NHibernate stuff. Castle...

Can I eagerly instantiate instances registered as singletons using castle windsor?

In castle windsor, when registering instances with a singleton lifecycle, is there a way to eagerly instantiate them (rather then having them initialized the first time they are injected)? Update: I figured some more details would be helpful here: These instances contain some initialization code that would be advantageous to run at s...

How does DI actually do the injection to a property?

I searched my brains out and wasn't able to find a suitable answer, so here we go! I have the following property in each of my forms or objects: private RootWorkItem m_RootWorkItem; [RootWorkItem(Inject = true)] public RootWorkItem RootWorkItem { get { if (m_RootWorkItem == null) { m_Root...

How to access my singletons without using global state?

I know that Singleton pattern is bad because it uses global state. But in most applications, you need to have a single instance of a class, like a database connection. So I designed my Database object without using the singleton pattern but I instanciate it only once. My question is, how can I access my object in the low level classes ...

What is Dependency Injection ?

Possible Duplicate: What is dependency injection? Spring is the framework from where the concept Dependency Injection came to picture. What is purpose of DI ? How does it benefit ? How is it implemented ? ...

Limiting Dependency on Spring Without Losing Power of Framework

Simplified Architecture of Web Projects WAR spring dependency injection (most use XML) JAR DAO Domain The Problem: With Spring 3 and 2.5+ annotations building Repositories and services has become much easier to wire together. However, because often a @Service conceptually belongs in the JAR far mo...

Resolving automatic and manual dependencies

Hi! I´m having a little bit of trouble sorting a way to manage automatic resolved and manual dependencies in my classes. Let´s say I have two classes to calculate prices: one calculates how much I will charge for shipping and the other how much I will charge for the entire order. The second uses the first in order to sum the shipping p...

Techniques for dependency injection into a domain model

I have a domain model type. One of its numerous properties requires an ITranslationService to provide the ability to translate its return value into the appropriate language. Should I inject the ITranslationService into the constructor of the domain model type (thereby having to alter everywhere the type is instantiated and having to be...

Where to set the ModelMetadataprovider with DI when using MVC Turbine ?

To use your own ModelMetadataProvider you normally set it in the global.asax. I'm using MVC Turbine and I need to inject a dependency into my ModelMetadataProvider as well. Something like this: ModelMetadataProviders.Current = new MyModelMetadataProvider(ISomeDependency); How is this best accomplished with MVC Turbine? ...

Using Autofac for DI into WCF service hosted in ASP.NET application

I'm having trouble injecting services dependencies into my WCF service using Autofac 1.4.5. I've read and followed the Autofac wiki page on WcfIntegration but my debugging shows me that my WCF service is created by the System.ServiceModel.Dispatcher.InstanceBehavior.GetInstance() method and not by the AutofacWebServiceHostFactory. What a...

What should be injected as C'tor paramter under DI principles ?

I'm trying to understand which objects should be injected into an object and which should be created internally. If i have some List<int> (as data field) which holds infomation gathered during run time. it seems that i should init it in the c'tor instead of injecting it. but what about a hardware class which communicates through a CO...

Can spring container inject collaborators using custom methods?

Normally dependencies are injected via setters by the following configuration (http://static.springsource.org/sprin...beans-beanname) : <bean id="exampleBean" class="examples.ExampleBean"> <!-- setter injection using the nested <ref/> element --> <property name="beanOne"><ref bean="anotherExampleBean"/></property> <!-- sett...

What is the difference between Overloading and Dependency Injection?

Though DI in interface driven...I am still not clear as to what exactly differentiates this from basic overloading concept. Any C# examples would be helpful. EDIT : I read here the reason for my question that StreamReader can be seen as example of IoC/DI...how is this different totally from overloading? Or is it just semblance to DI ...

IOC Container type resolution and injection location

Is it best practise to resolve and inject concrete types at the edge of the domain model and then have these fall down through the domain? For example, having the container inject concrete types into MVC controller constructors in a web app, or service endpoints in a service based app? My understanding of container object graph wire up ...

Where to put IoC container configuration?

Is it a good practice to create another project in your solution just to configure the container and for registries? I'm wondering where should I put the container configuration, I currently have all the code in my global asax but it's getting messy as I add more registries and more advanced injections. ...

How to programmatically create bean definition with injected properties?

I want to programmatically add a bean definition to an application context, but some properties of that definition are other beans from that context (I know their names). How can I do this so that those properties will be injected? For example: GenericBeanDefinition beanDef = new GenericBeanDefinition(); beanDef.setBeanClass(beanClass)...

Looking for Dependency Injection examples and clear tutorials with Ninject 2.0 for C# ASP.NET (NOT MVC)

I have been searching for a while. I'm not new to dependency injection and have used StructureMap with several projects MVC and the like, but I felt like giving Ninject a go, so as not to miss out on the fun. I am trying to use Ninject with an existing web app which I am bringing up-to-date. I couldn't find on the blogs and wiki provi...