dependency-injection

Singleton Pattern Vs ContainerControlled LifeTImeManager in Unity

What is difference between Singleton Scoping In Unity Framework and Singleton Pattern as general? And with singleton pattern , you can not use mock object directly , you need to change some singleton code. So is the singleton Anti-Pattern? ...

How to have structuremap build instance based on type.

Ok so this might not be the best title but I am struggling with how to title this. Here is what I have thus far: I currently have data mappers for my objects. I define them in a registry like so. This allows me to get the type name of the object and combine that with the word Mapper and request it. Here is the code I am using: this.For...

Unity Container ResolutionFailedException when the mapping is correct in the config file

I was using a ServiceLocator which i was DIing with Unity public ServiceLocator(IUserStore userStore, IProdcutsStore productsStore, ...etc) {} public IUserStore UserStore { get { return userStore; } } This all worked fine, but I wanted lazy instantiation of the repositories as they have quite sparse use. So my ServiceLocator n...

DI, Constructor Injection, Modules, design patterns

Hello, I'm facing some architectural problems on the project I'm involved in. The project is an ASP.NET MVC 2 application that relies on DI and especially on constructor injection with Unity. The application is divided into several modules (each module is a set of assembies) that exposes services to other modules. Those services are reg...

What is the best way of using NLog with MEF?

Hello, I am wondering what is the best way to use NLog with Managed Extensibility Framework (MEF)? I have an application that support plugins using MEF architecture (Import and Exports etc) I want to add logging capability to my application. As a logging component I want to use NLog. What would you recommend? 1. Create a wrapper for N...

How to deal with errors and exceptions during dependency injection

As far as I have understood, dependency injection separates the application wiring logic from the business logic. Additionally, I try to adhere to the law of Demeter by only injecting direct collaborators. If I understand this article correctly, proper dependency injection means that collaborators should be fully initialized when they a...

Injecting property values with Unity - type conversion

Hi. I am using the Unity fluent API to inject property values on an object. My program obtains the value of the properties from an external configuration source, an xml file. The problem I am facing is that the property I am attempting to set is of type Int32, but the value, having been read from an xml file, is initially cast as a str...

What am I doing wrong with NSManagedObjectContext dependency injection?

I am trying to use NSManagedObjectContext dependency injection as recommended by Marcus Zarra -- I'm creating an M.O.C. in my AppDelegate and passing it as a retained property to each of my view controllers. Generally this seems to work well, but in a modal table view controller that presents data via an NSFetchedResultsController, I on...

How do I use Dependency Injection with wicket?

How do I convert the following example to use one of the wicket/IOC integration packages? I want to learn and understand the DI/IOC pattern. I have read a lot about it, but I've found it a little hard to grasp without digging into a code example. I have an example of a complete, working Wicket panel, which I think I want to convert to u...

Unity IoC and registering primitive types

Right then, I've run into a situation using Unity that I don't know how to solve/approach...Here's my problem. I'm developing a WPF application and I'm using MVVM (Prism Implimentation hence the Unity container). I have a ViewModel called MenuItemsViewModel (plural) which contains an IEnumerable of MenuItemViewModel (singular). In the...

is it practically possible to do good TDD (or BDD) without using any DI framework in java?

IMO one of the main characteristics of a good TDD is: testing your class (or actually unit) in isolation. When you do so, you are able to actually test single behavior in each test -- only one test will fall for a single problem you have. For this you first must verify that there are no static references from your class (including cons...

How to use custom injection attribute for properties when using StructureMap?

I would like to have my own injection attribute so that I am not coupling my code to a particular IOC framework. I have a custom injection attribute that my code uses to denote that a property should be injected. public class CustomInjectAttribute : Attribute {} Fictitious example below... public class Robot : IRobot { [CustomInje...

How to avoid cyclic behaviour with Castle Windsor's CollectionResolver?

I am using Castle Windsor 2.5 in my application. I have a service which is a composite that acts as a distributor for objects that implement the same interface. public interface IService { void DoStuff(string someArg); } public class ConcreteService1 : IService { public void DoStuff(string someArg) { } } public class ConcreteServi...

Does this code smell?

Please educate me if I have code smell (violating SOLID principles, etc) Also how can I make use of IoC to make dependency injection better? Any help, tips, feedback is REALLY appreciated :) EDIT: Should all dependencies be injected from the constructor in the form of strings or should they be interfaces, if possible? For example, Logi...

Is it possible to Autowire the JDO PersistenceManager or only the PersistenceManagerFactory?

Is it possible to Autowire the JDO PersistenceManager? In the example below, only the PersistenceManagerFactory is Autowired, while the PersistenceManager is obtained using a getter and utility method before each operation. import org.springframework.orm.jdo.PersistenceManagerFactoryUtils; @Service public class MainServiceImpl impleme...

StructureMap nested dependency handling

I'm using StructureMap for dependency injection and I want to inject NHibernate sessions with it. I have the following code: private static Container _container { get; set; } static MyClass() { _container = new Container(r => { r.For<ISessionFactory>().Singleton() .Use(NHibernate.GetSessionFactory()); ...

Where is the @Autowired annotation supposed to go - on the property or the method?

Which is more correct? This (with the @Autowired annotation on the method)? @Controller public class MyController { private MyDao myDao; @Autowired public MyController(MyDao myDao) { this.myDao = myDao; } This (with the @Autowired annotation on the property)? @Controller public class MyController { @...

How to inject a spring's service bean into a JPA Entity ?

My problem is very similar to this one : Injecting fields via Spring into entities loaded by Hibernate The difference is that , I am using JPA2 entities , not hibernate . While the underlayer is still hibernate (3.5.5). My spring version is 3.0.4. What's the corresponding eventListeners in JPA's world ? Sample code from the original ...

With a windows Application (winapp) when/where should i Dispose of my UnitOfWork?

Hi folks, I've got a windows application that creates some threads to parse some txt files. Nothing too crazy. I'm using StructureMap Dependency Injection to create any instances of my Services and Repositories. So my Winform has a static property which returns the instance, based on what's been registered. Works great .. except I'm n...

How do I use Common Service Locator in Ninject 2

Changes in Ninject 2 say that Ninject support Common Service Locator, but how do I use it? I don't find any manual or sample. ...