8
голосов
1ответов
1447 просмотров

DI: Handling Life of IDisposable Objects

So I'm working on my DI/IoC Container OpenNETCF.IoC and I've got a (reasonable) feature request to add some form of lifecycle management for IDisposable items in the container collections. My current thinking is that, since I can't query an object to see if it's been disposed, and I can't get an...

307
голосов
15ответов
72493 просмотров

What's the difference between the Dependency Injection and Service Locator patterns?

Both patterns seem like an implementation of the principle of inversion of control. That is, that an object should not know how to construct its dependencies. Dependency Injection (DI) seems to use a constructor or setter to "inject" it's dependencies. Example of using Constructor Injection:...

1
голосов
1ответов
465 просмотров

Prefer Dependency-Injection over Partial Mocking?

I know this SO question, but it deals with the subject in more general terms. Should I prefer using partial Mocks over Dependency Injection? My question is based on the following quote from OCMock: id aMock = [OCMockObject partialMockForObject:anObject] Creates a mock object that can be us...

34
голосов
3ответов
7219 просмотров

Dependency injection and ASP.Net Membership Providers

I am in the process of creating a custom membership provider for an ASP.Net MVC website. The provider is being created as a separate class as part of a bigger library. There is a need for the back-end data store to be flexible as it could be an Xml File or SQL database. My initial thought was to ...

5
голосов
8ответов
1278 просмотров

What's a good metaphor for Dependency Injection?

A metaphor that stuck with me when programming non-DI systems is "a person playing with his/her toys". A person being an object and the person's toys being anything that object creates, stores, initializes, and manipulates. The toys can dispatch events when they reach a certain state, but they kn...

7
голосов
2ответов
412 просмотров

Dependency injection in NerdDinner - actually testing your repository or model

Consider a beginner dealing with Dependency Injection. We're analyzing two relevant classes in NerdDinner. DinnerRepository from the application: FakeDinnerRepository from the tests: They implement different logic, which of course is necessary, as the key idea here is to implement the IDinne...

2
голосов
2ответов
1581 просмотров

Stuck trying to get Log4Net to work with Dependency Injection

I've got a simple winform test app i'm using to try some Log4Net Dependency Injection stuff. I've made a simple interface in my Services project :- public interface ILogging { void Debug(string message); // snip the other's. } Then my concrete type will be using Log4Net... public cl...

3
голосов
3ответов
1994 просмотров

Is there something like PostConstruct for JAXB-annnotated classes?

Is there such a functionality in JAXB to perform operations on a class after it is unmarshalled i.e. after it is constructed by JAXB? If not, how could I achieve this?

12
голосов
4ответов
4015 просмотров

When to use Dependency Injection? When not to?

From what I understand, the trade-off here is a matter of added complexity. Maybe? It seems (always?) more decoupled to use Dependency Injection, but simpler (to many people) without it. From what I understand about everything in life, nothing is absolute, and there's a time and place for every...

3
голосов
6ответов
605 просмотров

Events in a Dependency Injection system go which way?

Up or down? I'm a very visual person. I'm thinking of my application as a hierarchy, where the top is the root and the bottom is a leaf. I'm also under the understanding that, in DI systems, containers are ignorant of their contained objects' responsibilities/functions. Instead, the contained o...

2
голосов
3ответов
286 просмотров

What is the best way to "adorn objects with functionality"?

I made the example below which enables a factory to pack objects with functionality, but the problem is that the functionality is divorced from the object. My ultimate goal is attach functionality such as log, and save and display which operates on the specific properties that each different ob...

12
голосов
3ответов
5239 просмотров

What role do delegates play in dependency injection?

In most examples of dependency injection, I see simple objects being injected, such as in the example below SecurityManager gets injected into MainApplication. However, it would seem natural to inject delegates as well, as in the example below LogHandler gets injected into MainApplication. Are ...

1
голосов
6ответов
371 просмотров

Is fetching an object from a container and example of dependency injection?

Is the example below Dependency Injection with regard to the Worker class? The Worker class isn't obtaining the ITool instance from a property setter or constructor, but is rather fetching it from a container? public MainClass { static void Main(string[] args) { ITool someTool = new...

8
голосов
2ответов
2010 просмотров

Best Aspect Oriented Framework for features / build performances in .net

In various projects I worked with, we had to use some AOP or dependency injection framework. We used Enterprise LIbrary, Unity and PostSharp. For now, Postsharp is my best choice when it comes to the flexibiity I get over how I generate my aspects. The only problem is the build time required...

2
голосов
6ответов
1336 просмотров

small footprint dependency injection java

I am looking for a very lightweight dependency injection framework for java. With minimum possible dependencies and minimum features. Just something along the following lines: receive a java.util.List of Classes, instantiate them and just auto-wire all the objects one into the other.

6
голосов
2ответов
6673 просмотров

spring: a bean that receives a list of Classes

I want to define in my Spring XML context a bean that has a property of the type List of classes: i.e. List<Class<?>> classes How do I send that bean a number of classes, say java.lang.String and java.lang.Integer? The list needs not be reusable, i.e. I will not refer to it in anoth...

63
голосов
6ответов
43500 просмотров

Unit Testing File I/O

Reading through the existing unit testing related threads here on Stack Overflow, I couldn't find one with a clear answer about how to unit test file I/O operations. I have only recently started looking into unit testing, having been previously aware of the advantages but having difficulty gettin...

7
голосов
2ответов
3071 просмотров

Autofac with Open Generics and Type Specified at Runtime

The documentation states that Autofac supports open generics and I am able to register and resolve in a basic case like so: Registration: builder.RegisterGeneric(typeof(PassThroughFlattener<>)) .As(typeof(IFlattener<>)) .ContainerScoped(); Resolve: var flattener = _...

1
голосов
2ответов
1194 просмотров

Castle Windsor (or other DI) - creating object based on parameter

I am pretty new to the whole DI/IoC thing, so bear with me... I have this kind of setting: interface IA interface IB interface IC abstract class A : IA class B : A, IB class C : A, IC interface IX interface IY interface IZ abstract class X : IX class Y : X, IY class Z : X, IZ B and C's const...

1
голосов
3ответов
1850 просмотров

Spring DI, Domain Model & best practices

Is it a good idea to not inject Domain Models in Spring. It saves some XML, and what is the use of injecting domain model anyway. For services and DAO, I want to decouple so I use DI, but Domain Model usually flows all the way from Web to DAO - sort of a vertical layer running through the horizo...

1
голосов
4ответов
439 просмотров

Injecting a resource into an abstract class

I have an abstract class, Shape, and I have a Canvas object that the Shape uses to set its position. I need to make sure that all Shapes have a Canvas object, preferably a Canvas object that is the same one across all shapes. I have thought of a couple of options: Add a canvas parameter to the...

2
голосов
1ответов
13591 просмотров

how do I configure autowire in spring

how do I configure autowire in spring

20
голосов
4ответов
1721 просмотров

Dependency Injection as a Language Feature?

Are there any existing modern-day programming languages that explicitly have dependency injection as a language feature, and if so, are there any examples of how such programming languages use their syntax to separate program dependencies from their concrete implementations? (Please Note: I'm no...

3
голосов
2ответов
2917 просмотров

Unity and delegate

I'm using the Unity dependency injection framework. I have two classes, that each take the same delegate parameter in the constructor. Each class should get a different method when resolved. Can I set this up without using attributes ? If not how would you do it with attributes?

151
голосов
14ответов
31618 просмотров

Dependency injection through constructors or property setters?

I'm refactoring a class and adding a new dependency to it. The class is currently taking its existing dependencies in the constructor. So for consistency, I add the parameter to the constructor. Of course, there are a few subclasses plus even more for unit tests, so now I am playing the game of g...

6
голосов
1ответов
1624 просмотров

Does an abstract class work with StructureMap like an interface does?

I am a big fan of StructureMap and use it in just about everything I do. I have only ever used it with interfaces though. I was wondering if anyone had any experience using with abstract classes? or...does it not support that type of wiring? If you got this to work can you post an example? T...

8
голосов
2ответов
3720 просмотров

Best way to use StructureMap to implement Strategy pattern

My web app has some slight variations in business logic and presentation logic depending on the type of user that is logged in. It seems like getting variations by injecting different concrete classes based on the user type is a good fit for DI. So I'm wondering what features of StructureMap I sh...

0
голосов
1ответов
219 просмотров

how to inject dependency into a custom control

I am using Dependency Injection to Inject interface into my few views. One of the requirement I need to Inject the interface into the custom control. I have tried using ServiceDependency attribute to inject interface , but it doesn't work. public interface ISearchService { void CustomizeLayo...

15
голосов
1ответов
5061 просмотров

Ninject 2.0 Constructor parameter - how to set when default constructor is also present?

I'm new to IOC containers and learning Ninject. I've using version 2.0, freshly downloaded from Github. I'm trying to set a string parameter on a constructor when a default constructor is also present. I've been stepping through the Ninject source but I'm insufficiently familiar with the pat...

5
голосов
4ответов
435 просмотров

Other than testing, how is Dependency Injection any better than static classes/methods?

Other than testability, what's the big advantage of utilizing D.I. (and I'm not talking about a D.I. framework or IoC) over static classes? Particularly for an application where you know a service won't be swapped out. In one of our c# application, our team is utilizing Dependency Injection in ...