Click here to Skip to main content
15,891,136 members
Articles / Web Development / ASP.NET

A N-Tier Architecture Sample with ASP.NET MVC3, WCF, and Entity Framework

Rate me:
Please Sign up or sign in to vote.
4.85/5 (91 votes)
11 Sep 2012CPOL48 min read 556.6K   31.7K   425  
This article tries to introduce a decoupled, unit-testable, deployment-flexible, implementation-efficient and validation-flexible N-Tier architecture in .NET
/*
 * Copyright © 2012
 * This code is for the codeproject article "A N-Tier Architecture Sample with ASP.NET MVC3, WCF and Entity Framework" at  
 * http://www.codeproject.com/Articles/434282/A-N-Tier-Architecture-Sample-with-ASP.NET-MVC3-WCF-and-Entity-Framework. 
 * Permission to use, copy or modify this software freely is hereby granted, 
 * provided that this copyright notice appears in the orginal or modified copies. 
 * 
 * This code isn't guaranteed to work correctly; it is your own responsibility for 
 * any result from using this code. 
 *                           
 * @description
 * 
 * @author  
 * @version July 18, 2012
 * @see
 * @since
 */

using System;
using Ninject;

namespace GH.Common.ServiceLocator
{
    public class ServiceLocatorImpl<IService> : IServiceLocator<IService>
    {
        /// <summary>
        ///   Get IService instance
        /// </summary>
        /// <returns></returns>
        public IService GetService()
        {
            return NinjectWraper.Kernel.Get<IService>();
        }

        /// <summary>
        /// </summary>
        /// <param name = "type"> an implementation type of this interface </param>
        /// <returns></returns>
        public IService GetServiceByType(Type type)
        {
            return (IService) NinjectWraper.Kernel.Get(type);
        }

        /// <summary>
        ///   Register IService
        /// </summary>
        /// <param name = "service">A physical instance of IService</param>
        public void RegisterService<T>() where T : class, IService
        {
            NinjectWraper.Kernel.Bind<IService>().To<T>();
        }


        /// <summary>
        ///   UnRegister IService
        /// </summary>
        /// <param name = "service">A physical instance of IService</param>
        public void UnRegisterService()
        {
            NinjectWraper.Kernel.Unbind<IService>();
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions