bean id="foo" class="com.ems.samples.spring.Foo"
property name="bar" ref="bar"/
/bean
bean id="bar" class="com.ems.samples.spring.Bar"
public class Foo {
private Bar bar;
public String getMessage() {
return "Foo" + bar.getMessage();
}
public void setBar(Bar bar) {
this.bar = bar;
}
}
public clas...
Maybe I am just blind, but I do not see how to use Guice (just starting with it) to replace the new call in this method:
public boolean myMethod(String anInputValue) {
Processor proc = new ProcessorImpl(anInputValue);
return proc.isEnabled();
}
For testing there might be a different implementation of the Processor, so I'd like...
DI/IOC: There are so many frameworks and the examples quickly get sticky with details particular to that framework. I find that I often learn a new technology best if I can learn its principles outside of a framework (the forest obscuring the trees).
My question: What are the simple principles of DI/IOC? I am looking for a (framework a...
It seems natural that a HttpServlet running in OSGi environment (i.e. registered in OSGi HttpService) would want to call some OSGi services to accomplish it's tasks. The question is how to obtain references to these OSGi service inside the servlet.
One way would be to inject dependencies into the HttpServlet instance that is being regis...
I have a custom membership/roles provider that I use in my MVC controllers that I also want to have accessible to ASP.NET MVC, so I can use AuthorizationFilters, etc. Since so many people have implemented custom providers I imagine many people have done this but I haven't figured it out or found postings that address this problem specifi...
If I understand correctly, the typical mechanism for Dependency Injection is to inject either through a class' constructor or through a public property (member) of the class.
This exposes the dependency being injected and violates the OOP principle of encapsulation.
Am I correct in identifying this tradeoff? How do you deal with this ...
Hi,
My question is as follows:
I have a base controller (ASP.Net MVC controller) called ApplicationController, and I want all my controller to inherit from it. this base controller has a ILogger property, marked with a [Dependency] attribute. (yes, I know I should use constructor injection, I'm just curious about this attribute).
I cre...
I'm a Lua novice. I'm unit testing Lua 5.1 code using Lunity and LeMock.
My class is StorageManager. I'm unit testing its load() method, which loads files from disk. I don't want my unit tests dependent on actual files on the actual disk to test that.
So, I'm trying to inject the I/O dependency with a mock object and verify that obj...
Hi Everyone!
i just tinkered around with Google Guice for Dependency Injection and started integrating it into my existing application. So far, so good. I have many classes which need, beside their dependencies, Strings, DataSources, et cetera. I know there are NamedBindings, but i really do not want to create an annotation for every si...
I'm attempting to use Unity for the first time and I think I might have bitten off more than I can chew. We have a n-tier application that has a base library with several abstract types and then several business scenario specific libraries on top of it w/ concrete types. For ex: The abstract type lead has two implementations, one in a Ne...
Is it possible to configure the Unity Dependency Injection framework to resolve by convention. So in other words if I have an ICustomerRepository when it tries to resolve this it will first look to see if there are any registered types and if not will then by convention try and resolve CustomerRepository class.
This would save a lot of ...
I've searched high and look for samples about using MEF for DI. I know its not DI but from what I hear (really hear in podcasts) it can be used as such...but I can't find any blog posts or samples.
I am using MEF in this project already (to support plugins) and thought it would be nice to leverage for DI also.
Maybe I am barking up the...
In most samples I have seen on the web, DI in MVC Controllers is done like this
public ProductController(IProductRepository Rep)
{
this._rep = Rep;
}
A custom ControllerFactory is used and it utilizes the DI framework of choice and the repository is injected.
Why is the above considered better than
public ProuctController()
{
...
I am using Composite Application Block. I have a class that uses constructor injection (using the [ServiceDependency] attribute on the constructor parameter) and it's working. But when I try to switch to using property injection (with the [ServiceDependency] attribute on the property), the injection is not happening (the property stays...
Today I've got this class:
public class SmtpEmailProvider : IMessageProvider
{
private readonly SmtpClientWrapper _smtpClientWrapper;
public SmtpEmailProvider(SmtpClientWrapper smtpClientWrapper)
{
_smtpClientWrapper = smtpClientWrapper;
}
To be able to mock the SmtpClient, I've wrapped it like this:
public c...
I am pretty new to the NInject binding, and here is what NInject describes.
TransientBehavior-A new instance of the type will be created each time one is requested.
SingletonBehavior-Only a single instance of the type will be created, and the same instance will be returned for each subsequent request.
OnePerThreadBehavior-One instance ...
I have a class that takes an array of interfaces in the constructor:
public class Foo<T1, T2> : IFoo<T1, T2>
{
public Foo(IBar[] bars)
{
...
}
}
My container registration looks as follows:
container.Register(AllTypes.Pick().FromAssemblyNamed("...")
.WithService.FirstInterface());
container.AddC...
I have a property on my classes for logging service.
private ILogger logger = NullLogger.Instance;
public ILogger Logger
{
get { return logger; }
set { logger = value; }
}
And I have this in my component registration:
container.AddFacility<LoggingFacility>(x => new LoggingFacility(LoggerImplementation.Log4net));
However, Wi...
How do I implement dependancy injection in C++ explicitly without using frameworks or reflection?
I could use a factory to return a auto_ptr or a shared_ptr. Is this a good way to do it?
...
When creating a designable .NET component, you are required to provide a default constructor. From the IComponent documentation:
To be a component, a class must
implement the IComponent interface and
provide a basic constructor that
requires no parameters or a single
parameter of type IContainer.
This makes it impossible to...