CRUDMethod Request Target(s) and Repositories

CRUDMethod Request Target(s) and Repositories

Abstract

WindnTrees CRUDMethod generalizes request data communication amongst CRUD interfaces and in this tutorial we'll understand how CRUDView with request "target" defined, communicates data between controller and repositories.

CRUD2CRUD is interface neutral, data centeric and promotes controller to controller communication. Programmers are required to extend repositories with one interface instead of writing interface for every repository.

Please read following tutorials if you need to understand CRUD2CRUD communication architecture.

  1. Why CRUD2CRUD Communication
  2. CRUD and CRUD2CRUD

Keywords: ASP .NET, MVC, MVVM, CRUD, WindnTrees, CRUDView, CRUD2CRUD, CRUDS
  • Benefits

    CRUDMethod (or CRUDM) in CRUD2CRUD architecture provides following benefits:

    1. One Interface
    2. Simple Programming Model
    3. Less Coding
    4. More Productivity
    5. Repository Abstraction (Support Multiple Databases)
    6. Data Architecture

    CRUDSList Example

    In this tutorial we'll implement a WindnTrees CRUDSList view comprised of array of CRUDViews each pointing a server side controller including CRUD repositories inside. Remember CRUDSList share same HTML view amongst multiple CRUDViews using single KnockoutJS binding.

    Our purpose of implementing this example is to learn how to use CRUDM (CRUDMethod) in HTML view using target (or __target) attribute with or without data input. Each server side WindnTrees CRUDController provides abstract CRUDLMRepository implementation leading toward no extra coding required at controller level.

    Programmers extend repositories and with m_TargetRedirection set to true controllers invoke appropriate repository methods besides default CRUDL (create, read, update, delete and list) methods.

    In this example following three repositories implement custom methods (AddNew, UpdateExisting, DeleteExisting, GetList, GetListTotal) for demonstration.

    1. CategoryRepository
    2. RatingRepository
    3. SkillLevelRepository

    Repository Implementation

    On server side, note that in original EntityRepository (that extends CRUDLMRepository) implementation custom CRUDLM methods are not required. CRUDL interface in CRUDLM repositories are sufficient for basic data processing and CRUDM (CRUDMethod) provides additional means of interfacing with extended repository methods using "__target" attribute at HTML view level. Extend CategoryRepository with following methods in addition to original implementation.

    1. AddNew,
    2. UpdateExisting,
    3. DeleteExisting,
    4. GetList,
    5. GetListTotal

    In EntityRepository implementation you must also implement list total method with "GetList", for example "GetListTotal".

    WindnTrees "__Target" Scripting and Explaination

    On client side, CRUDView provides CRUDL2CRUDL API mapping in all HTML view implementations. For example

    1. CRUDView controller "create" invokes "create" on server side controller repository,
    2. CRUDView controller "read" invokes "read" on server side controller repository, and so on.

    Additional repository methods invocation requires scripting mentioned as below:

    1. create({ __target:'AddNew', content: { } }) invokes "AddNew" on server side repository instead of "create".
    2. read({ __target:'FindObject', key: '1' }) invokes "FindObject" on server side repository instead of "read". (not implemented)
    3. update({ __target:'UpdateExisting', content: { } }) invokes "UpdateExisting" on server side repository instead of "update".
    4. list({ __target: 'GetList', query: { keyword: '', page: 1, size: 10 } }) invokes "GetList" on server side repository instead of "list" and so on.

    Still the interface remains same. Make sure data exchanged meets client and server side data definitions.

  • Controller Implementation

    In CRUD2CRUD application architecture client side "target" attribute based invocation are ASP .NET MVC Controller action methods. Read following section for more details.

    WindnTrees "Target" Scripting and Explaination

    In case if server side controller action invocation is required from client side CRUDView controller then implement as following:

    1. create({ target:'AddNew', content: { } }) invokes "AddNew" action on server side controller instead of "create".
    2. read({ target:'FindObject', key: '1' }) invokes "FindObject" action on server side controller instead of "read".
    3. update({ target:'UpdateExisting', content: { } }) invokes "UpdateExisting" action on server side controller instead of "update".
    4. list({ target: 'GetList', query: { keyword: '', page: 1, size: 10 } }) invokes "GetList" action on server side controller instead of "list" and so on.

    Note that CRUDView with "target" attribute invokes server side controller action while "__target" invokes server side repository method when m_TargetRedirection is set to true during controller construction process.

    Programmer may use both "target" and "__target" attribute that might involve server side controller action invocation with custom repository method invocations. Note that "target" will constitute server side controller action request while "__target" will be included in HTTP request headers for appropriate processing on server side.

    Current example does not implement "Target" attribute, programmer must implement for understanding.

    CRUD2CRUD is Interface Neutral

    CRUD2CRUD communication architecture is interface neutral that means programmer focus on data required for communication rather defining new interfaces for new controllers.

    Nuget Packages

    CRUD2CRUD example application depends upon following nuget packages.

    1. WindnTrees.Core
    2. WindnTrees.ICRUDS.Standard
    3. WindnTrees.CRUDS.Repository.Core

    Summary

    WindnTrees CRUDS architecture provide efficient means of developing interactive web pages with less and smart programming. Grow in repositories with simple controllers. Download and try CRUD2CRUD CRUDMethod "target" example from here.