I'm using JSON.NET to serialize and deserialize object for different purposes. I'm a big fan of DI but the code below gives me the chills. Is smells like bad code:
public class Foo : Baz
{
private readonly IBar bar;
public Foo()
: this(ObjectFactory.GetInstance<IBar>())
{ }
public Foo(IBar bar)
{
if ...
I've been thinking about whether it's possible to apply the DI pattern without incurring the cost of virtual method calls (which according to experiments I did can be up to 4 times slower than non-virtual calls). The first idea I had was to do dependency injection via generics:
sealed class ComponentA<TComponentB, TComponentC> : ICompon...
Once you have wired up the bean in the xml file, how to you instantiate the object?
Is it just like:
Myobject myObject = new MyObject();
And spring under the covers will perform the lookup based on the type?
Or do you have to use the applicationContext?
...
With NInject (preferably 2.0), what options do we have wrt wiring up our object dependencies in a web application?
Can they be defined in an XML configuration file?
Or does it have to be done via code?
...
I recently read Phil Haack's post where he gives an example of implementing Model View Presenter for ASP.NET. One of the code snippets shows how the code for the view class.
public partial class _Default : System.Web.UI.Page, IPostEditView
{
PostEditController controller;
public _Default()
{
this.controller = ne...
My current application allows users to define custom web forms through a set of admin screens. it's essentially an EAV type application. As such, I can't hard code HTML or ASP.NET markup to render a given page. Instead, the UI requests an instance of a Form object from the service layer, which in turn constructs one using a several RDM...
I'm having something like this:
class Root
{
public Root(IDependency dep)
{}
}
class Dependency:IDependency
{
public Dependency(int val)
{}
}
And I'm trying to obtain a reference to Root using ninject.
So i configure it like this
var module = new InlineModule(mod => mod.Bind<IDependency().To<Dependency>());
var kerne...
It's sometimes necessary when using dependency injection to provide the parameters to use in the constructor. This is something that's supported in Unity (and other dependency injection containers), so that when it tries to create an instance of the type, it can provide your arguments as parameters in the constructor.
My question is: is...
Hi - Im new to IOC and StructureMap and have an n-level application and am looking at how to setup the wirings (ForRequestedType ...) and just want to check with people with more experience that this is the best way of doing it!
I dont want my UI application object to reference my persistence layer directly so am not able to wire everyt...
Hi I don't have much knowledge on IoC/DI frameworks in .net framework. Can anyone give me links that explans IoC/DI in detail with few example in C#? I want go through it and get more idea about these frameworks. So that I can get the knowledge, where and How can I use these frameworks are useful in implementing the project.
Thanksnrk
...
I have this wcf method
Profile GetProfileInfo(string profileType, string profileName)
and a business rule:
if profileType is "A" read from database.
if profileType is "B" read from xml file.
The question is: how to implement it using a dependency injection container?
Mark Seemann author of book "Dependency injection in .net" Sugge...
I've created a web service client using Axis2. I would like to package the client into a jar, so I can use it in several other projects. The client uses the Axis2 WS-Security module 'rampart'. This module, rampart.mar (not a typo!) has to be present on the Axis 'repository path', in a directory called 'modules'. The client also requires ...
What is your advice?
I found most suitable for me solution - keep injectors and modules in enumeration classes.
Advantages:
injectors and modules created once,
injectors can be used from different classes while running application (not only at bootstrap),
injectors kept in one place and can be easily found.
Example:
import static r...
Situation: i need lazy dependency instantiation in some FooClass, so i pass Injector to class as a constructor parameter.
private final Injector m_injector;
public FooClass(@Named("FooInjector") Injector injector) {
m_injector = injector;
}
But guice doesn't permit to bind core classes (injectors, modules and etc). What is the soluti...
When developing Swing applications, I've typically defined a delegate interface for each UI component for action callbacks. For example, if there is a class, MyDialog, which contains a button, MyButton, then the ActionListener for MyButton will call MyDialog.Delegate.OnMyButtonClick(Event e). The UI component then becomes "dumb" and requ...
I have an interface (call it IAcmeService) that has multiple implementations.
FileSystemAcmeService
DatabaseAcmeService
NetworkAcmeService
The end-user needs to be able to select which implementation will be used and also save that selection.
Currently I'm configuring my IOC container (Unity) to register all the known implemenatation...
A Subject-Observer relationship isn't a dependency relationship: Observers don't need Subjects in order to exist, and vice versa. Yet the "wiring together" of publishers and subscribers is strongly reminiscent of Dependency Injection.
My shoot-'em-up game makes extensive use of the Observer Pattern. For example:
A controller object spa...
It's not quite clear to me how I can design so I keep the reference to the DI-container in the composition root for a Silverlight + MVVM application.
I have the following simple usage scenario: there's a main view (perhaps a list of items) and an action to open an edit view for one single item. So the main view has to create and show th...
Does the fact that Rails have an MVC approach mean that is has dependency injection?
Or is there a reason that we don't talk about dependency injection in Rails?
If Rails does have dependency injection, what does it consist of?
...
I'm trying to wrap my head around implementing MVC with as much useful abstraction as I can for purposes of automated unit testing. In the process, I came up against an interesting conundrum: How and where do I declare the mock object for my database?
Here's what I have.
ContactView is a form that implements IContactView. It has know...