dependency-injection

Spring autowire not behaving as expected

I have tried to autowire a bean for a test class using @Autowire, however the bean is not wired and I get this exception: Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.abc.MyDaoHibernateImpl] found for dependency: expected at least 1 bean which qualifies as autowire c...

Unity Application Block - Convert example from C# to VB

I'm attempted to convert the WPF Starter Kit from C# to VB.net and I'm doing really well, except for one area... Dependency Injection using the Unity Application Block. I have the following C# code block: Type viewModelType = viewModelAssembly.GetType(action.ViewModelTypeName); var notificationPolicy = unity...

Licensed component not playing well with DI design

We've licensed some third-party e-mail components and have developed a set of components for our system that uses them. These components are then loaded dynamically at runtime by an IoC container. However we have recently noticed in testing on a non-development machine that because the main .EXE which is "hosting" our components does no...

Unity Dependency Injection for WCF services

Can someone direct me to a good example of Unity Dependency Injection for WCF services? Any blog or msdn article will also help. ...

How should the web.config look like in Unity Dependency Injection for WCF services?

I am creating new instnace provider which resolve services through Unity. I am not sure how to add the configuration in web.config. Following is my service class. public class Service : IService { private IUnitOfWork _unitOfWork; private IMyRepository _myRepository; // Dependency Injection enabled constructors public Service(I...

Implementing a generic service factory or provider in Autofac

I have an interface, for example ISomeService. ISomeService provides a common service, but the implementations may vary. As such, they will have different dependencies. Consider: interface ISomeService { void DoSomething(); } class SomeServiceA : ISomeService { public SomeServiceA(DependencyOne one, DependencyTwo two) ...

Decomposition (modularity) in functional languages

Got an idea: functions (in FP) could be composed similar was as components in OOP. For components in OOP we use interfaces. For functions we could use delegates. Goal is to achieve decomposition, modularity and interchangeability. We could employ dependency injection to make it easier. I tried to find something about the topic. No luck....

JSF - Session-scoped managed bean does not have dependencies re-injected on session deserialization

I'm not sure if what I'm doing is wrong, or if I just missed an annotation or configuration item somewhere. Here's the situation: I have a JSF application with a session-scoped bean named SessionData. This bean has an application-scoped bean reference (of type ApplicationData) injected into it at creation time. This works ok when the...

Dependency injection - must the dependency be one of the class variables of the object into which it is injected?

All, I am writing a little dynamic site in php, and am trying to use dependency injection rather than globals. In my index, I create a $view object which contains the various elements to be displayed in the UI. In the index, I also have a switch($action){} structure that governs which controllers to require based on which item the use...

EJB dependency injection of remote service fails on Glassfish

I am unable to get dependency injection to work for my remote service and I cannot figure out why. I want an instance of RemoteService so I wrote. @EJB(name="RemoteService") private RemoteService service; And the Bean itself is defined with mappedName="RemoteService: @Stateless(mappedName = "RemoteService") public class RemoteService...

Injecting a generic factory in Guice

The following code is an example of a factory that produces a Bar<T> given a Foo<T>. The factory doesn't care what T is: for any type T, it can make a Bar<T> from a Foo<T>. import com.google.inject.*; import com.google.inject.assistedinject.*; class Foo<T> { public void flip(T x) { System.out.println("flip: " + x); } } interface Ba...

Modularity: Using Interfaces or not?

Since a few years, common sense seems to dictate that it's better to program against interfaces rather than against implementations. For high-level code this indeed seems logical, e.g. if I have a complex solver in my application, it seems better to have something like this: ISolver *solver = solverFactory.getSolver(); solver->solve(in...

Execute code before and after method?

In the service layer I have a classes that look something like: class MyService { public doSomething() { TelnetSession session = new TelnetSession(); session.open("username", "password"); session.execute("blah"); session.close(); } } In many classes I have to declare and open session and then at...

using Google Guice GraphViz extension and private modules.

Hi, I have simple private module: public class SomePrivateModule extends PrivateModule { @Override protected void configure() { bind(SomeInterface.class). annotatedWith(SomeAnotation.class). to(SomeClass.class); expose(SomeInterface.class).annotatedWith(SomeAnotation.class); bind(S...

How to inject dependencies into a self-instantiated object in Spring?

Let's say we have a class: public class MyClass { @Autowired private AnotherBean anotherBean; } Then we created an object of this class (or some other framework have created the instance of this class). MyClass obj = new MyClass(); Is it possible to still inject the dependencies? Something like: applicationContext.injectDepend...

Microsoft Unity- Issue With Resolve

Hello, I am looking to do this: container.Resolve(); When it does this, its going to inject a IDependency into the underlying entity object. However, the dependency stored within the container requires an object of type DependencyValue, which is supplied a value from a DependencyFactory. So long story short, the issue I'm having is ...

How do I use StructureMap with generic unclosed types using Scan with a "greedy" constructor

Between various Stack Overflow questions and blog posts there is a pretty reasonable amount of documentation on the topic of open generics and StructureMap. Unfortunately, I must be missing something as my attempts at using scan to perform the configuration along with a class implementation that has a "greedy" constructor have yet work. ...

how to create a Spring bean from a static inner class constructor?

I am trying to use the Spring Framework IoC Container to create an instance of class ThreadPoolExecutor.CallerRunsPolicy. In Java, I'd do it this way... import java.util.concurrent.RejectedExecutionHandler; import java.util.concurrent.ThreadPoolExecutor; ... RejectedExecutionHandler rejectedExecutionHandler = new ThreadPoolExecutor.Cal...

StructureMap 2.6 - How to do this in configuration file

Hi, Here is the c# code: var server = ******* some internal logic to determine server name **** var username = ******* some internal logic to determine user name **** var password = ******* some internal logic to determine password **** ObjectFactory.Initialize(x => { x.For<IService<bool>>(...

How to use Dependency Injection without breaking encapsulation?

How can i perform dependency injection without breaking encapsulation? Using a Dependency Injection example from Wikipedia: public Car { public float getSpeed(); } Note: Other methods and properties (e.g. PushBrake(), PushGas(), SetWheelPosition() ) omitted for clarity This works well; you don't know how my object implem...