MVC+EF three layer + abstract factory

Source: Internet
Author: User
Tags httpcontext

Mvc+ef three-storey + abstract plant project construction

Note: The project has been built two times, so the top-level namespace has zhh and ZHH2 differences, but the content of the schema is the same, you can treat zhh and ZHH2 as the same namespace

One: Rights Management

Two: Search

|-lucene.net (FAST) + Pangu participle (search word splitting)---more ambiguous than fuzzy query

|-fuzzy query like efficiency slow, full scan, can't split

Pangu participle, divided out the word, with the file exists in disk, file concurrency----lock lock-up new issues, efficiency slow, users need to wait

Producer Consumer mode---optimize file concurrency

Place participle in queue (in memory collection), Redis distributed queue

*sesion can store information only on one server

-out-of-process database session, poor performance, no one to use

Distributed Storage session Data

1-memcached memory operation, fast.

2-Distributed file (image) storage

3. Reverse Proxy Server: Nginx

4.WebService WCF

|-Hot Word statistics

Three: Workflow WF

Project Framework: Three layers + Abstract factory +spring.net

01IDao Layer

Referencing the model layer, the interface specification, the query returns IQUERYABLE<T>, deferred loading, the call will not generate the query, optimize performance

Expression--lambda Tree

Inquire:

Iqueryable<userinfo> loadentities (Expression<func<userinfo,bool>>where);

Paging:

iqueryable<userinfo> loadpageentities<tkey> (int pageIndex, int pageSIze, out int totalcount, Expression <func<userinfo, bool>> where, Expression<func<userinfo, tkey>>);

Increase:

UserInfo addentity (UserInfo entity);

By deleting:

BOOL Deleteentity (UserInfo entity);

Change:

BOOL Updateentity (UserInfo entity);

Because each interface needs to define the curd, it causes duplication, so, to encapsulate the base interface

Inherit base interface

Provide session interface to external idbsession

02Dao Layer

Referring to the Idao layer and the model layer, DAO implements the interface specification in Idao because it involves specific database operations, so, referencing EF components

DAO Layer Reference EntityFramework component

Raised issue: Cannot create context instances more than once in a request

Singleton mode: The control object has only one copy throughout the application cycle,

Although a single case can be solved, the new problem

, all users of the current application use the same object, and append data operations into the context object, which can cause memory consumption to become more and more difficult to release

Each request creates an EF context instance (unique within the thread)

When the request ends the release

HttpContext is a unique object within a thread

In the DAO layer define DBContextFactory.cs (defined at the DAO layer, Prevent circular referencing) context factory

The above professional wording

CallContext is a httpcontext.items internal object (unique within thread)

Since all DAO implements Crud,so, encapsulates a base class BaseDao.cs and creates an object using the context factory class

The focus is on the use of dbset<t>

The DAO layer subclass inherits the superclass and implements the Iuserinfodao interface

The DAO and BLL directly need communication, so, to create a new session layer (factory) to decouple

Define an abstract factory DAOAbsFactory.cs reflection with reflection

Call the factory class in the BLL layer to return an instance of the DAO layer with the interface type, reducing the degree of coupling between the BLL layer and the DAO layer

Abstract Factory class----Data Session layer

Decoupling of the Abstract Factory (reflection) business layer from the data access layer

-You can switch the DAO layer only if you need to change the configuration file

Abstract Factory Reference Assemblies

To create a session class to implement a session interface in Idao

After you have the session layer, create a new session factory (internally involving EF operations, unique within threads)

DBSessionFactory.cs

03IBLL

Reference

Encapsulation IBLL Layer Interface Super class

Sub-Interface Inheritance

04BLL

Reference

Package BLL Public Super class

Sub-class

05WebApp

Reference

MVC (test slightly)

MVC+EF three layer + abstract factory

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.