Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

This is my first time using Unity so bear with me for a moment. I have a sample Visual Studio 2012 solution with 4 projects (but only two of these projects will be used with Unity). This is the following setup of the projects:

  1. Database - WinForm project that displays a Master Detail Form
  2. DatabaseUtilities - A class library that implements the Repository pattern. The interface is called ISampleRepository.cs and the type is called SampleRepository.cs

Project Setup

I've been reading on Dependency Injection and I understand that the UnityContainer code gets placed in the starting location of where the application is going to run.

Should it go in Database.Program.cs or in a Bootstrapper.cs class that resides in the DatabaseUtilities project?

I ask because Program.cs is technically the entry point to the Database WinForm project.

Here's my code for Bootstrapper.cs:

using Microsoft.Practices.Unity.Configuration;

namespace DatabaseUtilities
{
    public class Bootstrapper
    {
        private static UnityContainer _container;

        public static ISampleRepository<Employee> LoadSampleRepository()
        {
            _container = new UnityContainer();
            _container.RegisterType(typeof(ISampleRepository<Employee>), typeof(SampleRepository));
            var obj = _container.Resolve<ISampleRepository<Employee>>();


            return obj;            
        }
    }
}

I'm thinking of referencing the Bootstrapper.cs from Program.cs in the Database project.

But would this be considered a best practice? Furthermore, I want to make sure that I don't shoot myself in the foot later on. Let's say I decide to implement another form from the MasterDetail form and I need to perform a different CRUD operation (i.e. an update operation). I want to be able to use my class that implements IRepository.

Am I looking at this from the right angle?

share|improve this question

closed as off-topic by Nick Udell, syb0rg, konijn, Brythan, jsanc623 Nov 4 '14 at 15:58

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

3  
This is more of a Programmers question I think. Have you considered moving your composition root / entry point in a separate assembly, so you can remove references to your IoC container in the UI project? –  Mat's Mug Oct 7 '14 at 11:21
    
Good point on both ends. –  burritowarrior Oct 7 '14 at 16:20

Browse other questions tagged or ask your own question.