Ejemplo n.º 1
0
        public static LibraryService CreateLibraryService()
        {
            IUnitOfWork          uow;
            IBookRepository      bookRespository;
            IBookTitleRepository bookTitleRepository;
            IMemberRepository    memberRespository;

            //读取配置文件中的持久性策略的配置节
            string persistenceStrategy = ConfigurationManager.AppSettings["PersistenceStrategy"];

            //根据读取的配置节创建不同的持久化对象
            //EF
            if (persistenceStrategy == "EF")
            {
                uow                 = new Repository.EF.EFUnitOfWork();
                bookRespository     = new Repository.EF.Repositories.BookRepository(uow);
                bookTitleRepository = new Repository.EF.Repositories.BookTitleRepository(uow);
                memberRespository   = new Repository.EF.Repositories.MemberRepository(uow);
            }
            //NHibernate
            else
            {
                uow                 = new Repository.NHibernate.NHUnitOfWork();
                bookRespository     = new Repository.NHibernate.Repositories.BookRepository(uow);
                bookTitleRepository = new Repository.NHibernate.Repositories.BookTitleRepository(uow);
                memberRespository   = new Repository.NHibernate.Repositories.MemberRepository(uow);
            }

            return(new LibraryService(bookTitleRepository, bookRespository, memberRespository, uow));
        }
        public static LibraryService CreateLibraryService()
        {
            IUnitOfWork          uow;
            IBookRepository      bookRespository;
            IBookTitleRepository bookTitleRepository;
            IMemberRepository    memberRespository;

            string persistenceStrategy = ConfigurationManager.AppSettings["PersistenceStrategy"];

            if (persistenceStrategy == "EF")
            {
                uow                 = new Repository.EF.EFUnitOfWork();
                bookRespository     = new Repository.EF.Repositories.BookRepository(uow);
                bookTitleRepository = new Repository.EF.Repositories.BookTitleRepository(uow);
                memberRespository   = new Repository.EF.Repositories.MemberRepository(uow);

                #region not implemented yet
                //uow = new Repository.NH.NHUnitOfWork();
                //bookRespository = new Repository.NH.Repositories.BookRepository(uow);
                //bookTitleRepository = new Repository.NH.Repositories.BookTitleRepository(uow);
                //memberRespository = new Repository.NH.Repositories.MemberRepository(uow);
                #endregion
            }
            else
            {
                uow                 = new Repository.NH.NHUnitOfWork();
                bookRespository     = new Repository.NH.Repositories.BookRepository(uow);
                bookTitleRepository = new Repository.NH.Repositories.BookTitleRepository(uow);
                memberRespository   = new Repository.NH.Repositories.MemberRepository(uow);
            }

            return(new LibraryService(bookTitleRepository, bookRespository, memberRespository, uow));
        }
        public static LibraryService CreateLibraryService()
        {
            IUnitOfWork uow;
            IBookRepository bookRespository;
            IBookTitleRepository bookTitleRepository;
            IMemberRepository memberRespository;

            string persistenceStrategy = ConfigurationManager.AppSettings["PersistenceStrategy"];

            if (persistenceStrategy == "EF")
            {
                uow = new Repository.EF.EFUnitOfWork();
                bookRespository = new Repository.EF.Repositories.BookRepository(uow);
                bookTitleRepository = new Repository.EF.Repositories.BookTitleRepository(uow);
                memberRespository = new Repository.EF.Repositories.MemberRepository(uow);

                #region not implemented yet
                //uow = new Repository.NH.NHUnitOfWork();
                //bookRespository = new Repository.NH.Repositories.BookRepository(uow);
                //bookTitleRepository = new Repository.NH.Repositories.BookTitleRepository(uow);
                //memberRespository = new Repository.NH.Repositories.MemberRepository(uow);
                #endregion
            }
            else
            {
                uow = new Repository.NH.NHUnitOfWork();
                bookRespository = new Repository.NH.Repositories.BookRepository(uow);
                bookTitleRepository = new Repository.NH.Repositories.BookTitleRepository(uow);
                memberRespository = new Repository.NH.Repositories.MemberRepository(uow);
            }

            return new LibraryService(bookTitleRepository, bookRespository, memberRespository, uow);
        }