dependency-injection

Google Guice vs. JSR-299 CDI / Weld

Weld, the JSR-299 Contexts and Dependency Injection reference implementation, considers itself as a kind of successor of Spring and Guice. CDI was influenced by a number of existing Java frameworks, including Seam, Guice and Spring. However, CDI has its own, very distinct, character: more typesafe than Seam, more stateful and less X...

MEF = may experience frustration?

UPDATE As I've tried to get MEF working throughout my application, I'm coming across more an more places where I just don't get why it's not automatically creating my library when I expect it to. I think it all comes back to what Reed was saying about needing MEF to create everything. So right now, I have an XML reader class that need...

Gin / Gwt / Eclipse: com.google.gwt.inject.Inject cannot be resolved to a type

I'm trying to use GIN (Guice for GWT) within eclipse. The tutorial says to add a line to my module xml file: <inherits name="com.google.gwt.inject.Inject"/> However, when I do this Eclipse reports an error "com.google.gwt.inject.Inject cannot be resolved to a type" I've added gin.jar, aopalliance.jar and guice.jar as referenced l...

Dependency Injection & Singleton Design pattern

How do we identify when to use dependency injection or singleton pattern. I have read in lot of websites where they say "Use Dependency injection over singleton pattern". But I am not sure if I totally agree with them. For my small or medium scale projects I definitely see the use of singleton pattern straightforward. For example Logger...

Inject filter into Zend_View

Hi! I wish to set some properties in MyFilter with constructor injection but it seems impossible with Zend_View::addFilter(string $filter_class_name) since it loads a new instance upon usage. MyFilter implements Zend_Filter_Interface. Can I somehow inject an instance of a filter to an instance of Zend_View? Closing since it (hopefully...

Reinject dependencies of a freshly deserialized object

If a program has literally just deserialized an object (doesn't really matter how, but just say BinaryFormatter was used). What is a good design to use for re-injecting the dependencies of this object? Is there a common pattern for this? I suppose I would need to wrap the Deserialize() method up to act as a factory inside the containe...

castle windsor container not wiring properties correctly

I have a class that i want to instantiate thru castle in configuration. public class MyMappings : IMappings { Mapping FirstMapping { get; set; } Mapping SecondMapping { get; set; } OtherType ThirdMapping { get; set; } OtherType FourthMapping { get; set; } Mapping FifthMapping { get; set; } OtherType SixMapping { ...

Which pattern to use for logging? Dependency Injection or Service Locator?

Consider this scenario. I have some business logic that now and then will be required to write to a log. interface ILogger { void Log(string stuff); } interface IDependency { string GetInfo(); } class MyBusinessObject { private IDependency _dependency; public MyBusinessObject(IDependency dependency) { _de...

Tapestry 5 and Spring beans with same interface

I have a problem with Tapestry 5 and Spring integration. Problem occurs if I have a multiple beans that implement the same interface and I try to inject them with @Inject annotation. Of course I got an exception. I found a tutorial that says that in that case I have to use @Service annotation too but now I'm getting org.apache.tapestr...

Is there a dependency injection framework for Smalltalk?

I'm running Pharo and I'm just in a use case that sort of screams for Dependency Injection à la Guice. Is there something similar for Smalltalk? I understand that you can sort of do it all by foot, by just passing in your dependencies explicitly. But that feels awkward and verbose to me. ...

How to inject dependencies in Collection form ??

How do I wire up dependencies where the dependency is in the form of a collection ?? For Example: public class Ninja { public List<IShuriken> Shurikens {get;set;} public IKatana Katana {get;set;} public void Attack() { // some code goes here to use weapons and kill people } } How do i use a container like Ninject in a case like t...

Instance management with Dependency injection (DI)

Hello I'm trying to understand how DI exactly works. I'm currently using Windsor as DI container. I use this to load my services dynamically in code without direct reference. But I have change behaviour and want to know a bit more on the instance mgmt using DI. I have a web app projct, here is a WCF service using PerCall as instancemo...

Unity: Replace registered type with another type at runtime

We have a scenario where the user can choose between different hardware at runtime. In the background we have several different hardware classes which all implement an IHardware interface. We would like to use Unity to register the currently selected hardware instance for this interface. However, when the user selects another hardware, t...

how do use Ninject with class libraries I am developing?

If I am working on a class library how do I make use of Ninject here? i.e., from the internal class library point of view and also from the client code? For example: should the class library have its own IOC set up, or should it always assume the client code will supply? if no (ie it's up to the client to have the IOC in place) then w...

What is a kernel (with regards to dependency injection)?

I see the term kernel used a lot but I am not sure what it means. Can you give an example. ...

When using Dependency Injection with StructureMap how do I chooose among multiple constructors?

I'm trying to get structuremap to build Fluent Nhibernate's SessionSource object for some of my intregration tests. The only problem is that Fluent's concrete implementation of ISessionSource (SessionSource) has 3 constructors: public SessionSource(PersistenceModel model) { Initialize(new Configuration().Configure(), m...

How do I handle classes with static methods with Ninject?

How do I handle classes with static methods with Ninject? That is, in C# one can not have static methods in an interface, and Ninject works on the basis of using interfaces? My use case is a class that I would like it to have a static method to create an unpopulated instance of itself. EDIT 1 Just to add an example in the Topolog...

JSR-303 dependency injection and Hibernate

Spring 3.0.2, Hibernate 3.5.0, Hibernate-Validator 4.0.2.GA I am trying to inject Spring dependencies into a ConstraintValidator using: @PersistenceContext private EntityManager entityManager; I have configured the application context with: <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFacto...

Ninject - Asp.net Mvc: Multiple projects in solution

Hello, I was trying Ninject in a Asp.net Mvc application and I was wondering what the best practice is for using Ninject if you have more than 1 project in your solution. I guess all projects need some kind of Loader which you initialize in the global.asax? Kind regards, Pickels ...

Hidden Features of Google Guice

Google Guice provides some great dependency injection features. I came across the @Nullable feature recently which allows you to mark constructor arguments as optional (permitting null) since Guice does not permit these by default: e.g. public Person(String firstName, String lastName, @Nullable Phone phone) { this.firstName = che...