Click here to Skip to main content
Click here to Skip to main content
Articles » Web Development » ASP.NET » Samples » Downloads
 
Add your own
alternative version

YaBlogEngineMVC - A Tiny Blog Engine written in ASP.NET MVC

, 9 Apr 2013
This article presents a very small scale blog engine developed using ASP.NET MVC, Entity Framework and SQLServer.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace YaBlogEngineMVC.Models
{
    public class UnitOfWork : IUnitOfWork, IDisposable
    {
        yaBlogDbEntities entities = null;
        ICategoryRepository categoryRepo = null;
        IBlogRepository blogRepo = null;
        ICommentsRepository commentsRepo = null;

        public UnitOfWork()
        {
            entities = new yaBlogDbEntities();
            categoryRepo = new CategoryRepository(entities);
            blogRepo = new BlogRepository(entities);
            commentsRepo = new CommentsRepository(entities);
        }

        public ICategoryRepository CategoryRepo
        {
            get
            {
                return categoryRepo;
            }
        }

        public IBlogRepository BlogRepo
        {
            get
            {
                return blogRepo;
            }
        }

        public ICommentsRepository CommentsRepo
        {
            get
            {
                return commentsRepo;
            }
        }


        public void Dispose()
        {
            // If this function is being called the user wants to release the
            // resources. lets call the Dispose which will do this for us.
            Dispose(true);

            // Now since we have done the cleanup already there is nothing left
            // for the Finalizer to do. So lets tell the GC not to call it later.
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (disposing == true)
            {
                //someone want the deterministic release of all resources
                //Let us release all the managed resources
                entities = null;
            }
        }

        ~UnitOfWork()
        {
            // The object went out of scope and finalized is called
            // Lets call dispose in to release unmanaged resources 
            // the managed resources will anyways be released when GC 
            // runs the next time.
            Dispose(false);
        }
    }
}

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)

About the Author

Rahul Rajat Singh
Software Developer (Senior)
India India
I Started my Programming career with C++. Later got a chance to develop Windows Form applications using C#. Currently using C#, ASP.NET & ASP.NET MVC to create Information Systems, e-commerce/e-governance Portals and Data driven websites.

My interests involves Programming, Website development and Learning/Teaching subjects related to Computer Science/Information Systems. IMO, C# is the best programming language and I love working with C# and other Microsoft Technologies.
  • Microsoft Certified Technology Specialist (MCTS): Web Applications Development with Microsoft .NET Framework 4
  • Microsoft Certified Technology Specialist (MCTS): Windows Communication Foundation Development with Microsoft .NET Framework 4
 
If you like my articles, please visit my website for more: www.rahulrajatsingh.com[^]
Follow on   Twitter   Google+   LinkedIn

| Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 10 Apr 2013
Article Copyright 2013 by Rahul Rajat Singh
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid