Skip to content
/ Beef Public

The Business Entity Execution Framework (Beef) framework, and the underlying code generation, has been primarily created to support the industrialization of API development.

License

Notifications You must be signed in to change notification settings

Avanade/Beef

Repository files navigation


Logo


Introduction

Beef framework has been primarily created to support the industralisation of API development.

A means to have software developers focus directly on the accelerated delivery of business value; with consistently higher quality outcomes at an overall lower cost.

The key industralisation goals are:

  1. Value – focus on business value, not on boilerplate
  2. Acceleration – improve velocity; reduce costs and time to market
  3. Simplicity – increase effective usage and minimize learning
  4. Standardized – increase knowledgeable resource pool
  5. Consistency – improve overall quality and maintainability
  6. Flexibility – enable innovation and evolution easily over time
  7. Confidence – reduced delivery timeframes and risk

Demonstration

The following video (includes sound) provides a high-level demonstration of Beef and its capabilities.

beef-demo.mp4

Version 5

NOTE: A new major version of Beef, verison 5, was released on 26-Jan-2023. The samples have been updated accordingly, as has the related documentation. As such, development on the previous version (v4.x) will for the most part halt; only significant issues will now be addressed (for a period of time). The new version is a major refactoring (improvement and simplification) with respect to the underlying runtime primarily, and although effort was made to minimize impacts on upgrading from v4, this was unfortunately unavoidable. Guidance is provided to assist with upgrading from v4.2.x to v5.x where applicable.


Composition

Beef is ostensibly the code-generation engine, and solution orchestration, that ultimately takes dependencies on the following capabilities to enable the end-to-functionality and testing thereof in a standardized (albiet somewhat opinionated) manner:

  • CoreEx - provides the core runtime capabilties (extends .NET core);
  • UnitTestEx - provides extended unit and intra-domain integration testing;
  • DbEx - provides extended database management capabilties;
  • OnRamp - provides the underlying code-generation engine functionality.

Prior to version 5.x, Beef was all encompassing. These capabilities have been extracted, simplified and refactored to be first class frameworks in their own right, and made into the repos listed above. This allows them to be used and maintained independently to Beef; therefore, offering greater opportunities for reuse versus all-or-nothing.


Rapid enterprise-grade API development

As a result of the Beef Architecture, supporting Framework and included Code Generation capabilities, enterprise-grade APIs can be developed in a matter of hours, not days, in a standardized and consistent manner.

The APIs created will have the following capabilities out-of-the-box with limited developer effort, so the developer can focus on the key business value:

  • Rich Entity (DTO) functionality including INotifyPropertyChanged, IEditableObject, IEquatable, ICopyFrom, ICleanUp, IPrimaryKey, etc.
  • Rich Reference data capabilities, including caching, optimized serialisation, and enriched API endpoints.
  • Rich Validation capability to simplify and ensure data integrity and consistency.
  • CRUD (Create, Read, Update and Delete) for Database (Stored procedures and Entity Framework), Cosmos DB and HttpAgent in a standardized manner.
  • Paging (skip and top) and resulting total count, that flows from API through to the underlying data source in a consistent and seamless manner.
  • ETag (concurrency) and If-Match/If-None-Match handling.
  • JSON response field filtering (include/exclude) to minimize resulting payload size (e.g. $fields=firstname,lastname)
  • HTTP Patch support, where required, in a simplified and consistent manner.
  • An end-to-end intra-domain integration testing approach enables effective tests to be built easily and quickly.
  • Event publishing (and subscribing) to enable an event-driven architecture.
  • Runtime capabilities can be added, where applicable, using the out-of-the-box .NET framework Dependency Injection (DI) capabilites.
  • An approach and tooling to automate and manage database using DbEx set up, configuration, and deployment.

To implement these included capabilities would literally take months/years to build and test; these are available for developers to use immediately, and contribute back if so inclined. The capabilities and implementations have been influenced by Microsoft's best practices for cloud applications; specifically:

To get started a .NET Core template capability is provided to enable you to get a solution up and running in minutes.


Architecture

Beef has been developed to encourage the standardisation and industrialisation of the tiering and layering within the microservices (APIs) of an Application Architecture.


API-enabled domain-based channel-agnostic architecture

The conceptual architecture is as follows; with Beef being targeted specifically at implementation of the API tier.

Domains

The key concepts are as follows:

  • Channel-agnostic - the APIs are based around the key entities and the operations that can be performed on them:

    • APIs represent the key trust boundary; as such, they make no assumptions on the consumer. The APIs will always validate the request data, and house the application’s functional business and orchestration rules.
    • APIs should not be developed to service a specific user interface interaction; as the APIs are agnostic to the consumer. The consumer has the responsibility of coordinating across API calls.
  • Domain-based – the APIs are based around, and encapsulate, the capabilities for a functional domain:


Microservices

An architectural pattern for creating domain-based APIs:

  • Is a software architecture style in which complex applications are composed of small, independent processes communicating with each other using language-agnostic APIs.
  • These services are small, highly decoupled and focus on doing a small task, facilitating a modular approach to system-building.
  • Implementation independence:
    • Loose coupling – should have its own persistence repository; data is duplicated (synchronized), not shared; eventual consistency; no distributed transactions.
    • Polyglot persistence / programming – use the best persistence repository to support the storage requirements; use a mix of programming languages (fit-for-purpose). Note: Beef provides a C# / .NET implementation approach as one option.
    • Eventual consistency - for the most part, eventual consistency is good enough; real-time distributed transactional integrity is rarely required (although generally desired). An asynchronous messaging system, such as Queues or a Service Bus, can be leveraged to orchestrate cross domain data (eventual) consistency.

“Micro” doesn’t imply number of lines of code; but a bounded concept / business capability within your Domain. - http://herdingcode.com


Tiering and layering

The architecture supports a domain-based channel-agnostic microservices approach. The API service endpoints represent a light-weight facade for the Business (domain logic) tier, that is ultimately responsible for the fulfillment of the request.

The following represents the prescribed tiering and layering of the architecture:

Layers

Given this architecture, the .NET Solution you create using Beef should adhere to the prescribed solution structure.

Each of the key layers / components above are further detailed (Xxx denotes the entity name); further documentation for each is available via the provided links:


Event-driven

To support the goals of an Event-driven Architecture Beef enables the key capabilities; the publishing (Producer) and subscribing (Consumer) of events (messages) to and from an event-stream (or equivalent).

Layers

  • Producer / Publisher - the publishing of events is integrated into the API processing pipeline; this is enabled within either the Data (where leveraging the transactional outbox pattern) or Service orchestration layers to ensure consistency of approach. Beef is largely agnostic to the underlying event/messaging infrastructure (event-stream) and must be implemented by the developer (unless provided, see Azure ServiceBus).

  • Consumer / Subscriber - a event subscriber is then implemented to listen to events from the underlying event/messaging infrastructure (event-stream) and perform the related action. The event subscriber is encouraged to re-use the underlying logic by hosting the Beef capabilities to implement. The Domain logic layer can be re-leveraged to perform the underlying business logic on the receipt of an event (within the context of a subscribing domain).

Additionally, Beef has capabilities to support (and generate) the Transactional Outbox Pattern where there is a requirement for events to be sent reliably (with no message loss); i.e. to guarantee at-least-once sent semantics within the context of the underlying data update (currently only supported for Database repository).


Framework

A comprehensive framework has been created to support the defined architecture, to encapsulate and standardize capabilities, to achieve the desired code-generation outcomes and improve the overall developer experience.

Standardized approach, ensures consistency of implementation:

  • Reduction in development effort.
  • Higher quality of output; reduced defects.
  • Greater confidence in adherence to architectural vision; minimized deviation.
  • Generation and alike enables the solution to evolve more quickly and effectively over time.

A key accelerator for Beef is achieved using a flexible code generation approach leveraging OnRamp.


Packages

The key tooling capabilities for Beef are enabled by the following NuGet packages (version 5+). The included change log details all key changes per published version.

Assembly Description NuGet
Beef.CodeGen.Core Code generation console tool. NuGet version
Beef.Database.Core Database and data management console tool. NuGet version
Beef.Database.MySql MySQL database and data management console tool. NuGet version
Beef.Database.Postgres PostgreSQL database and data management console tool. NuGet version
Beef.Database.SqlServer SQL Server database and data management console tool. NuGet version
Beef.Template.Solution Solution and projects template. NuGet version

The following is provided to support a level of version 4.x backwards compatibility.

Assembly Description NuGet
Beef.Test.NUnit Unit and intra-domain integration testing framework (backwards compatibility only). NuGet version

Samples

The following samples are provided to guide usage:

Sample Description
My.Hr A sample as an end-to-end solution walkthrough to demonstrate the usage of Beef within the context of a fictitious Human Resources solution. The main intent is to show how Beef can be used against a relational database (SQL Server) leveraging both direct ADO.NET (with stored procedures) and Entity Framework (EF) where applicable.
MyEf.Hr A sample as an end-to-end solution walkthrough to demonstrate the usage of Beef within the context of a fictitious Human Resources solution. The main intent is to show how Beef can be used against a relational database (SQL Server) leveraging only Entity Framework (EF).
Cdr.Banking A sample as an end-to-end solution to demonstrate Beef being used to solve a real-world scenario. This demonstrates an implementation of the CDR Banking APIs leveraging a Cosmos DB data source.
Demo A sample as an end-to-end solution to demonstrate the tiering & layering, code-generation, database management and automated intra-domain integration testing. This is primarily used to further test the key end-to-end capabilities enabled by Beef.

Additional documentation

The following are references to additional documentation (these are all accessible via links within this and other documentation):

General

Solution

Code-generation


External links of potential interest

  • Versioning - article, implementation - Beef has no specific support or opinion with respect to versioning approach and/or implementation.
  • Domain-driven design - Wikipedia, Fowler, Microsoft authored articles: article, article, article and article - Beef encourages the DDD approach, and is why Entity naming and convention is foundational within.

License

Beef is open source under the MIT license and is free for commercial use.


Getting started

To start using Beef you do not need to clone or fork the repo; you just need to create a solution with the underlying projects using the prescribed solution structure, including referencing the appropriate NuGet packages. To accelerate this a .NET Core template capability is provided to enable you to get up and running in minutes.

See the following for example end-to-end solution/project creation; each demonstrating the same API functionality leveraging different data sources to accomplish:

Otherwise, follow along with the following sample tutorials that will provide a more in-depth walkthrough solving a defined functional problem:

  • My.Hr - microservice against a SQL Database using both stored procedures and entity framework.
  • MyEf.Hr - microservice against a SQL Database using entity framework.
  • Cdr.Banking - microservice against an Azure CosmosDB data source.
  • Xyz.Legacy - CDC implementation against a legacy database publishing messages to Azure Service Bus.

Contributing

One of the easiest ways to contribute is to participate in discussions on GitHub issues. You can also contribute by submitting pull requests (PR) with code changes.


Coding guidelines

The most general guideline is that we use all the VS default settings in terms of code formatting; if in doubt, follow the coding convention of the existing code base.

  1. Use four spaces of indentation (no tabs).
  2. Use _camelCase for private fields.
  3. Avoid this. unless absolutely necessary.
  4. Always specify member visibility, even if it's the default (i.e. private string _foo; not string _foo;).
  5. Open-braces ({) go on a new line (an if with single-line statement does not need braces).
  6. Use any language features available to you (expression-bodied members, throw expressions, tuples, etc.) as long as they make for readable, manageable code.
  7. All methods and properties must include the XML documentation comments. Private methods and properties only need to specifiy the summary as a minimum.

For further guidance see ASP.NET Core Engineering guidelines.


Tests

NUnit is used for unit testing.

  • Tests need to be provided for every bug/feature that is completed.
  • Tests only need to be present for issues that need to be verified by QA (for example, not tasks).
  • If there is a scenario that is far too hard to test there does not need to be a test for it.
  • "Too hard" is determined by the team as a whole.

Code reviews and checkins

To help ensure that only the highest quality code makes its way into the project, please submit all your code changes to GitHub as PRs. This includes runtime code changes, unit test updates, and updates to the end-to-end demo.

For example, sending a PR for just an update to a unit test might seem like a waste of time but the unit tests are just as important as the product code and as such, reviewing changes to them is also just as important. This also helps create visibility for your changes so that others can observe what is going on.

The advantages are numerous: improving code quality, more visibility on changes and their potential impact, avoiding duplication of effort, and creating general awareness of progress being made in various areas.