Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is my ASP.NET MVC Project Strucure. (all are seperate projects)
1. FT.Web
2. FT.Entities
3. FT.BLL.Contracts
4. FT.BLL.Logic
5. FT.Data.Contracts
6. FT.Data.Sql

Here I'd like to create the Service Layer (contract and Logic) dependency in Web project. We can add contract project reference but not Logic Project since web project only required contracts not implementation.

I am able to do it by adding the Bll.Logic reference to Web Project but I dont like it since its tightly coupled with Web Project. Is there any other way that we can achieve the dependency without adding the reference? btw, I am using Unity.MVC3 for dependency Injection.
Posted
Updated 17-Feb-14 10:33am
v2
Comments
Sergey Alexandrovich Kryukov 17-Feb-14 16:45pm    
Dependency injection is not something you "add". This is not an ingredient, this is a design pattern... What's the problem?
—SA

1 solution

Here is my code for Unity configuration

XML
<?xml version="1.0"?>
<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
  <typeAliases>

    <!-- Services -->
    <typeAlias alias="IUserAccountService" type="FT.BLL.Contracts.IUserAccountService, Antony.BLL.Contracts" />
    <typeAlias alias="UserAccountService" type="FT.BLL.Logic.UserAccountService, Antony.BLL.Logic" />


  </typeAliases>
  <container>
    <register type="IUserAccountService" mapTo="UserAccountService" />
  </container>
</unity>



And Bootstrapper.cs code

C#
private static IUnityContainer BuildUnityContainer()
       {
          // var container = new UnityContainer();

           var section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
           IUnityContainer container = new UnityContainer().LoadConfiguration(section);

           // register all your components with the container here
           // it is NOT necessary to register your controllers

           // e.g. container.RegisterType<ITestService, TestService>();

           return container;
       }


This configuration setting expects both service projects need to be added in Web project. But I just want to add Interface reference only. not implementation layer reference.
Thanks. Any Help.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900