dependency-injection

"Multiple bindings" error when calling ninject2.Get<ConcreteClass>()

I'd like to do something like this: ConcreteClass foo = ninject2.Get<ConcreteClass>( new ConstructorArgument("bar", "qux")); ninject2.Bind<ConcreteClass>().ToConstant(foo); ... ConcreteClass foo = ninject2.Get<ConcreteClass>(); // fail! When I try, I get the error Error activating ConcreteClass. More than one matching bindings ...

SEAM: How to get EntityManager and Logger in a class that is loaded dynamically?

Hi, I have a background service that runs every 10 min. This service queries the DB for jobs to execute a will load a class with a different business logic according to the job (using Class.forName()). They implement the same Interface, of course. I declared those classes to be SEAM components but when I try to use the entityManager ...

Can CDI be lessened towards JSE?

JSR-330 dependency injection can be applied to both JSE and JEE environments, while JSR-299 is titled "Contexts and Dependency Injection for the Java EE platform". Except strictly JEE-oriented features, what CDI features make sense on JSE either? Any examples available? Thanks! [Revised] Here's Weld on JSE. ...

Explicit property injection breaks other properties in Unity

Dependency injection stops working for all properties, except the one specified explicitly. Controller: public class MyController : Controller { [Dependency] public int RefreshInterval { get; set; } [Dependency] public IReportService ReportService { get; set;} Web.config: <register type="My.Web.Controllers.MyControll...

"Classes should never perform work involving Dependencies in their constructors."

So, the quote comes from "Dependency Injection in .NET". Having that in consideration, is the following class wrongly designed? class FallingPiece { //depicts the current falling piece in a tetris game private readonly IPieceGenerator pieceGenerator; private IPiece currentPiece; public FallingPiece(IPieceGenerator pieceGene...

Dependency injection containers: how to handle objects that aren't a dependency of anything?

When we use a dependency injection container, ideally we pull only a single-top level object from it (e.g. an instance of Program) and let the rest of the application be composed automatically by the container. However, sometimes there are objects which are not a dependency of anything else, yet we want to have them in the object graph....

Autofac in ASP.Net MVC

As a newbie to Autofac, I'm trying to figure out how to register my Repository for my Controllers. The Repository takes a web service in its constructor to communicate with the server. This application is multi-tenant and the tenant name is accessed in the MVC route data. Since I can't access the route data within global.asax like most...

IOC across visual studio projects?

Hi I'm trying to retro-fit (bad idea I know, but better late than never) IOC and DI into an existing solution. The code base is made of up about 30 projects, each which have classes in them which have little or no visibility to the outside world. Being relatively new to the IOC thing I'm trying to use best practise when reworking the ...

StructureMap singletons varying by argument?

Using StructureMap, is it possible to have a singleton object for each value of an argument? For example, say I want to maintain a different singleton for each website in a multi-tenancy web app: For<ISiteSettings>().Singleton().Use<SiteSettings>(); I want to maintain a different singleton object corresponding to each site: ObjectFac...

Fatal error: Declaration of registerContainerConfiguration must be compatible with that of Kernel::registerContainerConfiguration

Do anyone know why this occurs? as far I can get, the child class method is declared in the same way as parent's. Thanks! here is my kernel code: <?php require_once __DIR__.'/../src/autoload.php'; use Symfony\Framework\Kernel; use Symfony\Components\DependencyInjection\Loader\YamlFileLoader as ContainerLoader; use Symfony\Component...

Dependency Injection and AppSettings

Let's say I am defining a browser implementation class for my application: class InternetExplorerBrowser : IBrowser { private readonly string executablePath = @"C:\Program Files\...\...\ie.exe"; ...code that uses executablePath } This might at first glance to look like a good idea, as the executablePath data is near the code ...

How to dependency inject a class / type?

I'm struggling with a design problem and I don't want my code to become a mess because of a bad solution. Rather than give a poor analogy I'll just explain my exact case. I'm trying to write a clone of Wii Play Tanks, and I'm having trouble designing the Tank classes. Tank itself is the only such class, it uses dependency injection for ...

Can the object created in IoC container be called Singleton. If not - why?

can the object created in IOC container can be called Singleton if yes why if no why? Can anybody explain me in detail in simple words how IOC conatiner exactly manages the objects.. ...

Ninject - how to inject during object lifetime?

Hi, I'm just getting started with dependency injection. I've read the Ninject wiki and its very clear on how to inject dependencies where a single instance of the dependency is required, using constructor, property or method injection. But how do you handle the case where your class needs to construct objects during its lifetime (after ...

How to instantiate unitofwork

Hi. I am using Dependency Injection pattern to resolve correct instance of mine UnitOfWork. When I am using only one type mapping, all is ok unityContainer.RegisterType<IUnitOfWork, UnitOfWork>(); The problem occurs when I am using two type mappings for the same interface: unityContainer.RegisterType<IUnitOfWork, UnitOfWork1>(); ...

MVC2 Using Unity IoC - How are controllers resolved?

I have a question concerning how the Unity container I have set up is resolving controller dependencies. I've been searching around for an explanation of this but haven't found anything that is real clear on the subject. And maybe the answer is staring me in the face... Take a look at the following code that I'm sure many MVC guys hav...

PHP project with excellent OOP design for studying purposes

Hello, I've recently became interested in proper OOP design in web applications. I think I understand most of the principles and design patterns but sometimes I have problem with putting them into practice. I use MVC and I think I am able to design controllers and views in OOP way. The problem I face is with models. I'm particularly obs...

I want to know , Is spring dependency injection create singleton object ? If yes how it manage internally?

I want to know , Is spring dependency injection create singleton object ? If yes how it manage internally? .. I want to know at what time this singleton object is created and destroy. ...

Injecting HttpContext in Ninject 2

In my asp.net mvc application I'm using Ninject as a DI framework. My HttpAccountService is used by my controllers to get info from and to cookies. For this I need the HttpContext.Current in the HttpAccountService. As this is a dependency I injected it throught the constructor as such: kernel.Bind<IAccountService>() .To<HttpAccount...

Structuremap resolve tpye with parameters

Hi, I have a problem.... Lest say I have a class like this one: public class A: InterfaceA { private FileInfo _fileInfo = null; public A(FileInfo fileInfo) { this._fileInfo = fileInfo; } ... } and another one: public class B: InterfaceB { private A _classA = null; public B(A classA) { ...