-1

I should register DI.

    private static void Initialize(ContainerBuilder builder)
    {
        builder.RegisterType<Logger>().As<ILogger>().SingleInstance();
        //...
    }

And this is clear to me. But what if I have 17 projects in my solution. Projects are related, one project is web project, some projects are providers, some projects are libraries, Core project etc. For example:

in Project1, I have class_A1 and this class should inject Class_A2 from same project
in Project2, I have class_B1 and this class should inject Class_B2 from same project
in Project3, I have class_C1 and this class should inject Class_C2 from same project
...
in Project17, I have class_K1 and this class should inject Class_K2 from same project

Of course I have some complicated scenarios, like inject class from Project3 to Project14 etc.
Should I do registration in every project separately? Or there is better way?
Thanks for help.

Anant Dabhi
  • 10,864
  • 3
  • 31
  • 49
Raskolnikov
  • 3,791
  • 9
  • 43
  • 88
  • did you mean without reference a project into other project? – Mirza Danish Baig May 12 '15 at 08:32
  • Which DI framework are you using? What does it's help docs say on the matter? – David Arno May 12 '15 at 08:41
  • @David In one Solution I have Autofac, in other Unity. But I am asking for general advice, not depend on framework. I could not find answer, if I could I would not ask you. – Raskolnikov May 12 '15 at 08:47
  • @Mirza No, I could reference when that make sense, but I don't want reference everything to web project. Because in some cases project should be used without web, or some library should not depends on other project. – Raskolnikov May 12 '15 at 08:53
  • @user2451446 you should be add a reference in order to use its code, otherwise doesn't need to add. – Mirza Danish Baig May 12 '15 at 08:55

1 Answers1

0

You don't need to register types in every project if all the projects are part of a same solution. Generally in any solution, you will have one main project which I would expect to use all of the other projects in your solution and you can add your registration in the main project.

But in some solution you may have projects that are not directly referred by main project, if this is the case then you have two options IMHO

  1. You can add other projects as a reference to your main project and register the types in you main project OR
  2. You can create a new project, say, infrastructure and add all the projects as reference to the infrastructure project and register the types and then just add infrastructure as reference to your main project and call the method which takes care of the type registration from main project.
kodebot
  • 1,718
  • 1
  • 22
  • 29