jigsmshah
jigsmshah

Reputation: 165

Repository Pattern and 3 Tier Architecture

I am facing the same dilemma as it is mentioned in this Question.

Repository Pattern in Layered Architecture

Is Dependency Injection the way to proceed ahead? Is this Patterns suitable for ASP.Net MVC type framework?

I would like to know how the industry is implementing the Repository Pattern in 3 Tier Architecture.

Regards

Upvotes: 2

Views: 3133

Answers (1)

Shoaib Shaikh
Shoaib Shaikh

Reputation: 4585

There is answer given in the question you just mentioned. You really don't need to reference DAL in directly in you code, instead of this you should use IoC. This way you can easily separate the dependency between the layers. and using IoC can also make this possible to make unit test of your BLL Repository methods.

Q:Is Dependency Injection the way to proceed ahead? Is this Patterns suitable for ASP.Net MVC type framework?

A:Repository Pattern is suitable for MVC. the main advantage of using repository pattern with IoC/Dependency Injection is to separate layer of concern and make you classes unit testable.

Q:I would like to know how the industry is implementing the Repository Pattern in 3 Tier Architecture.

A: as described in the other question you mentioned. Repository Pattern in Layered Architecture. you can try implementing repository pattern in you Business Logic Layer. and in presentation layer you can using IoC to setup you classes and their dependencies.

 public static class ServiceLocator
    {
        public static readonly IUnityContainer IoC = new UnityContainer();

        static ServiceLocator()
        {
            IoC.RegisterInstance(IoC, new ContainerControlledLifetimeManager());
        }
    }

This is how you can setup IoC in global.ascx

        ServiceLocator.IoC.RegisterType<ICampusRepository, CampusRepository>();
        ServiceLocator.IoC.RegisterType<IReasonRepository,ReasonRepository>();

Upvotes: 1

Related Questions