dependency-injection

How do I get a smooth debug experience in Visual Studio 2008 when using dependency injection?

What are the best practices around providing a smooth debug experience in Visual Studio 2008 when using dependency injection (DI)? Specifically, suppose I have a solution with 3 projects: MySolution: - ConsoleApp - ServiceInterface - ConcreteService ConsoleApp has a reference to the ServiceInterface project, and uses a D...

Google Guice vs. PicoContainer for Dependency Injection

My team is researching dependency injection frameworks and is trying to decide between using Google-Guice and PicoContainer. We are looking for several things in our framework: A small code footprint - What I mean by a small code footprint is we don't want to have dependency injection code litter everywhere in our code base. If we ne...

How to provide dependency injection via StructureMap for a custom role provider with WCF?

We're going to be using a custom role provider with WCF. The overridden method GetRolesForUser will require the use of an already existing RoleRepository. Now, with a run-of-the-mill class, we'd construct it using StructureMap and the RoleRepository dependency would be injected via the constructor. However, it's WCF that does the co...

How to configure Unity to apply a "constant" string for a constructor parameter during RegisterType() ?

This is what my service contructor looks like: public Service(string path) and I'm configuring unity like this: IUnityContainer container = new UnityContainer(); container.RegisterType<IService, Service>(); which of course is not correct. The path parameter needs to be specified, and I would like this to be configurable from the Ap...

Use Rhino Mocks to create an in-memory database for use while developing code and user interface

Hi Everyone, I've been struggling with this all morning and I may be completely on the wrong track since Rhino Mocks was originally designed for Unit Testing. However, I have a couple of resusable backend components that handle Authentication and 'Blogging' like features of a website, each contains their own data access layer. While d...

Replace Spring.Net IoC with another Container (e.g. Ninject)

Hey all, I'm curious to know if it's possible to replace Spring.Net's built-in IoC container with Ninject. We use Ninject on my team for IoC in our other projects so I would like to continue using that container if possible. Is this possible? Has anyone written a Ninject-Spring.Net Adapter?? Edit I like many parts of the Spring.Net...

Good practices for handling multiple config files with DI frameworks

In my current solution I have 18 projects and most of them have their own configuration files (app.config or web.config). Each project uses single shared BLL assembly. I'm using Autofac to handle dependencies but haven't come with a decent way of managing my configuration. Configuration entries are roughly the same, but values are differ...

Injecting data to a WCF service

I have WCF services structured like suggested by Miguel Castro. This means that I have set everything up manually, and have a console application hosting my services using ServiceHost objects. I want to keep my service classes thin, and they are currently just passing on calls to behavior classes. My problem now is unit testing the ser...

Dependency Inject (DI) "friendly" library

I'm pondering the design of a C# library, that will have several different high level functions. Of course, those high-level functions will be implemented using the SOLID class design principles as much as possible. As such, there will probably be classes intended for consumers to use directly on a regular basis, and "support classes" th...

Can dependency injection prevent a circular dependency?

Project#1 has some interfaces and classes that project#2 references. Now I want to use the implementation of Project#2 in Project#1 but vs.net complains about a circular dependency. If I was to use dependancy injection in Project#1 and bind to the implementation in Project#2 (since it adheres to the interface contract), will this work ...

What is the intention of nInject modules?

I'm a complete newbie to nInject I've been pulling apart someone else's code and found several instances of nInject modules - classes that derive from Ninject.Modules.Module, and have a load method that contains most of their code. These classes are called by invoking the LoadModule method of an instance of StandardKernel and passing i...

How to inject event handlers into events with Unity

How can I inject (attach) event handlers to .net events of instances created by the Unity IoC container? Example: I have a class that reports errors via a standard .net event: class CameraObserver { public event Action<Exception> UnhandledException; [...] } I have another class that is reponsible for handling those even...

structuremap Buildup() a user control

2 questions here. I have a page that I already use setter DI to insert a service layer using the following snippet from another post. var application = (HttpApplication)sender; var page = application.Context.CurrentHandler as Page; if (page == null) return; ObjectFactory.BuildUp(page); How would I do the same for a user control t...

StructureMap setter injection in open generic type?

Using StructureMap, I'm trying to use setter injection on an open generic type. I have an abstract generic class: public abstract class Foo<T1, T2> : IMyInterface<T1,T2> { public ISomeDependency Bar { get; set; } } I want to use Setter Injection to resolve "Bar" on any inheritors of Foo. I know I can do this using the [SetterDepe...

DI container, factory, or new for ephemeral objects?

When dealing with objects that require data known only at runtime, such as a username and password, where should object instantiation happen: by using new, in a factory, or in a DI container? For example, I could just new an object once I have the data: UserCredentials creds = new UserCredentials(dialog.getUsername(), dialog.getPas...

How to use/configure Unity Container IOC in my situation

Hi, I have some trouble implementing the Unity IOC into my project reading from config file. Here is what I have 1) ClasslibraryA 2) ClasslibraryB that references ClasslibraryA 3) Winforms App that references ClasslibraryB Note: SomeOther app will reference ClassLibraryA, eg. a web service. ClasslibraryA will have to be configured...

Best way to order menu items injected by an IoC/plugin Framework

One of the common things I've seen done in applications built on IoC/plugin frameworks is to add commands to menus or toolbars from the dynamically loaded plugins. For example, the application's default plugins supply actions like "New, Open, Save" that show up in the context menu for a certain item in the workspace. A new plugin may a...

Unit testing CRUD operations when data source is configured in application server properties

Hi all! Please, tell me: How can I write unit test (e.g. with JUnit) for operation "insert into some table" when many properties for normal application work are saved in config files for application server? Thanks!a ...

ObjectContext never derives from an interface?? How do you apply DI/IoC in case of multiple types of ObjectContext?

If you have a system that has multiple types of object contexts. For Eg: BillingObjectContext, HumanResourceObjectContext etc. All derive from ObjectContext but ObjectContext Class does not implement any specific interface like IObjectContext. How would you apply DI/IoC in case of multiple types of ObjectContext say using Ninject? ...

Unity Dependance Injection of a WCF service via web.config

I have a project that I am experimenting with DI in. I am using Unity and things seem to work well for normal assemblies and the injections. I am trying to further break dependencies with WCF services. The WCF service that I want to inject is created at runtime currently without using DI and I don't use the VS .net generated proxies: ...