GithubHelp home page GithubHelp logo

renaudcalmont / aspnetcore-mongodb-sandbox Goto Github PK

View Code? Open in Web Editor NEW
13.0 5.0 5.0 54 KB

Web API application with repository pattern and isolated business logic using ASP.NET Core 1.0, MongoDB, Docker, unit and integration tests

License: MIT License

C# 99.44% HTML 0.56%

aspnetcore-mongodb-sandbox's Introduction

aspnetcore-mongodb-sandbox Build Status

Built container is available on Docker hub

The goal of this project is:

MVP for an enterprise-grade WebAPI... Still a lot going on!

What it is so far:

An evolving pile of good practices collected over years from different real-world situations and technologies (mostly ASP.NET MVC anyway)

Here are some principles in mind. Any relevant design pattern might be added

  • Well-designed interfaces are the key to architecture - both inheritance and layer definition
  • Layers help enforcing SRP and are easily activated via dependency injection
  • Data are kept in POCO classes "IModel" from which "IEntity" is a particular case denoting an atomic persistent data type.
  • Data are manipulated by specialized classes. Ideally, every operation in these classes is stateless.
  • The business logic should be reusable from many communication channel (SOAP, restful HTTP, server-side web pages, rich client...).
  • As a key component, the business logic should be thouroughly covered by specific unit tests
  • Full-stack integration tests are still relevant as automated check before any QA campaign

The layers are separated as follow:

Layer Responsibility, class types
Web API Controller and associated Views + authentication
Business Logic Handler (both for Entities and other Models)
Data Access Repository (for Entities), other persistent data
Domain Objects Models + layers definition (Interfaces)

A typical web request have parameters in its URL and/or the JSON representation of a View in its body. Said request is sent by the framework to a relevant controller according to routing rules, after authentication of the origin.

The Controller should be as thin as possible, managing the transformation of the View in a corresponding Model/Entity and HTTP stuff. It then delegates further processing of the Model/Entity to the corresponding Handler.

The Handler manages any operation on the data contained in the Model/Entity. In case of an Entity, it will delegate any persistence operation to the corresponding Repository.

The result of the operation, either useful artefact or error message, is followed all the way up to the Controller to construct the HTTP response.

How to use it on your development machine:

Clone the project and open it in VS code. The prerequisite to run are:

  • A running MongoDB server on localhost with default config
  • .NET Core Command Line Tools

You should then be able to start the WebAPI from the debugger in VS code.

Alternatively, type dotnet run from a command line in the src/Sandbox.Server.Http sub-folder.

A sample docker-compose.yml script is provided. After running an initial docker-compose up from the command line on a Docker-enabled machine, the WebAPI will respond at http://localhost:5000 (same as running in the debugger) and mongodb will respond at its default location mongodb://localhost:27017.

The MongoDB container port mapping is for convenience only. So you can safely remove it to avoid conflict with any other running MongoDB daemon.

TODO:

  • Security - or consider the excellent IdentityServer4
    • roles and ACL
    • integrate OWIN for OAuth2 authentication
    • deeply implement ownership for multi-tenancy?
    • manage session tokens
  • Logging
    • send errors and security notifications to an external ELK stack
  • Testing
    • make an example unit test
    • make an example integration test
  • Functionality
    • use WebSockets (SignalR) to broadcast changes in real-time
    • archive older versions of an entity at update and delete operations
    • consider adopting a specification such as OData or JSON API - or keep it going its own way...
    • add minimal client-side libraries (such as bower and gulp)
  • Persistence
    • get the connection strings from an external resource directory for production environment
  • Yeoman
    • write the generator for the entire project
    • consider a generator for adding a model once the skeleton is stabilized
  • Consistency
    • documentation

Credits:

Trying here to keep track of and thank all the building blocks composing this project

Feel free to PR on this document or the project's code.

aspnetcore-mongodb-sandbox's People

Contributors

abauzac avatar renaudcalmont avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.