EF6 Codefirst+repository+ninject+mvc4+easyui Practice (end)

Source: Internet
Author: User
Tags windows azure sdk azure sdk

Preface

    • This is the last article in this series, although the example is here to stop, but the learning of these technologies can not be stopped. Although this example is the basis of comparison, as I said in the first article, the purpose of this series is not to say some high-end architecture design, but as an entry level, to build a simple example of learning EntityFramework6 and to design, manage, encode the process.
    • Should part of the Park Friends request, blog changed a refreshing template. Before the template is also to learn, so according to the other template style, the blog Park template to fix it. Although this is not the main purpose of blogging, but still learn a lot from it, such as the application of small plug-ins, running JS and CSS control style. So "hands-on" is the most effective way to get new skills.
    • The solution sample is left without a description of the service layer, which is explained in this article. Next is to introduce some of the corresponding learning resources to help themselves and everyone to progress together.

Construction of the Factory plant

    • Now, when designing the software, we seldom use the New keyword to create objects, because the complexity of the current hierarchy of the system is more complex. In order to effectively reduce the degree of coupling between tiers, we will use some other design methods. such as the previously mentioned dependency injection, such an IOC container has a lot. But the service layer I still use the factory pattern in design mode to reduce vertical dependencies between tiers.
    • First we set up a cache class, because the creation of objects consumes resources and time. With caching, you can use the same object without having to create it repeatedly, but instead load the cache directly, which can improve the efficiency of your system. The reference code is as follows:
 Public classDatacache {//gets the cache value of the current application specified CacheKey         Public Static ObjectGetCache (stringCacheKey) {System.Web.Caching.Cache Objcache=Httpruntime.cache; returnObjcache[cachekey]; }        //sets the cache value for the current application to specify CacheKey         Public Static voidSetcache (stringCacheKey,Objectobjobject) {System.Web.Caching.Cache Objcache=Httpruntime.cache;        Objcache.insert (CacheKey, objobject); }    }

    • Next, we use reflection to dynamically create the objects of the concrete. This allows us to create objects when we need them, effectively improving the performance of the system. The reference code is as follows:
       //do not use cache        Private Static ObjectCreateobjectnocache (stringAssemblyPath,stringclassnamespace) {            Try            {                ObjectObjType =Assembly.Load (assemblypath).                CreateInstance (Classnamespace); returnObjType; }            Catch//(System.Exception ex)            {                //string Str=ex. Message;//Logging error Logs                return NULL; }        }        //using the Cache        Private Static ObjectCreateObject (stringAssemblyPath,stringclassnamespace) {            ObjectObjType =Datacache.getcache (classnamespace); if(ObjType = =NULL)            {                Try{ObjType=Assembly.Load (assemblypath).                    CreateInstance (Classnamespace); Datacache.setcache (Classnamespace, objType);//Write Cache                }                Catch//(System.Exception ex)                {                    //string Str=ex. Message;//Logging error Logs                }            }            returnObjType; }

    • Finally, it is very easy to create a data-tier interface object, just to provide the assembly path and namespace name, such as the user interface object creation reference code as follows:
        // Create the S_userrepository data-tier interface. public        static  is_userrepository Creates_user ()        {            string " . S_userrepository";             object ObjType = CreateObject (assemblypath, Classnamespace);             return (is_userrepository) objType;        }

    • After the new Web service file Sysuserservice.asmx is created at the service layer, we can invoke the methods in the user interface layer, such as the name of the first user who reads the user list. The reference code is as follows:
Private ReadOnlyIs_userrepository Blls_user =Dataaccess.creates_user (); [WebMethod] Public stringHelloWorld () {intTotal ; stringStrName = Blls_user.getinfo ("",Ten,1, outTotal ). FirstOrDefault ().            UserName; return "Hello World:"+StrName; }

    • At this, the creation of the service layer has been completed. Although the code is not written, it is possible to build a complete solution for the service layer in accordance with the above pattern. Source has been placed on the network, click to download .

Notes

    • If you don't know entityframework yet, you can watch a few video resources from Microsoft experts.

    • If you know entityframework can see the following blog directly, this is the Entity Framework 6 Code first series blog, the new series with the Entity Framework 6 and MVC5 built, write very well. The main contents include:
    1. Create an entity Framework data model
    2. Implement basic CRUD functionality
    3. Sorting, filtering, and paging
    4. Connection resiliency and command interception
    5. Code first migration and deployment
    6. Creating a complex data model
    7. Reading associated data
    8. Update associated data
    9. Asynchronous and stored procedures
    10. Concurrent processing

........

Blog link address: Click here to jump

There's also the EntityFramework team's blog address.

    • If you already know a lot about entityframework and need to build an enterprise application architecture and solution for it, you can look at the following open source architecture. The open-source framework on CodePlex EFMVC that the master should contain the following classes:

Technologies

    1. Windows Azure SDK
    2. ASP. NET MVC 4 RTM
    3. ASP. NET Web API
    4. Entity Framework Code First 5
    5. Autofac
    6. AutoMapper
    7. Nunit
    8. Moq

  Patterns & Practices

    1. Domain driven Design (DDD)
    2. Test-driven Development (TDD)
    3. Repository Pattern & Generic Repository
    4. Unit of work Pattern
    5. Dependency Injection

Click here to view link Address

EF6 Codefirst+repository+ninject+mvc4+easyui Practice (end)

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.