mateuszradny / Hermsoft.EntityFrameworkCore.DynamicOData

Automatic OData v4 API based on EF Core configuration.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Contributors Forks Stargazers Issues MIT License LinkedIn


Logo

Hermsoft.EntityFrameworkCore.DynamicOData

This is a library that makes it easy to expose OData APIs based on DbContext definitions. By using this library you can save time on required controller code, model edm, etc.
Explore the docs »
· Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap
  5. Contributing
  6. License
  7. Contact
  8. Acknowledgments

About The Project

Product Name Screen Shot

Library created as part of the (https://100commitow.com) competition

(back to top)

Built With

(back to top)

Getting Started

This is an example of how you may give instructions on setting up your project locally. To get a local copy up and running follow these simple example steps.

Prerequisites

This is an example of how to list things you need to use the software and how to install them.

  • .NET Core 9.0

Installation

dotnet add package Hermsoft.EntityFrameworkCore.DynamicOData

NuGet Version NuGet Version NuGet Downloads

(back to top)

Usage

Configuration

The only thing you need to do to use this library is to call the function AddDynamicOData():

// Add services to the container.
builder.Services.AddDbContext<SalesDbContext>(options =>
    options.UseSqlServer(builder.Configuration.GetConnectionString("SalesConnectionString"))
);

builder.Services.AddDbContext<HRDbContext>(options =>
    options.UseSqlServer(builder.Configuration.GetConnectionString("HRConnectionString"))
);

builder.Services.AddControllers()
    .AddDynamicOData<SalesDbContext>(options =>
    {
        options.RoutePrefix = "sales";
        options.IsEntityTypeAutorized = type => false;
    })
    .AddDynamicOData<HRDbContext>(options =>
    {
        options.RoutePrefix = "hr";
        options.IsEntityTypeAutorized = type => false;
        options.WithRequestHandlerService<HRRequestHandlerService>(); // optional
    });

// ...

app.MapControllers();

After that you can navigate to /sales/entity_name or /hr/entity_name

Custom request handler

You can customize a way of handling requests by implementing IRequestHandlerService or override default implementation DefaultRequestHandlerService and next pass it to function WithRequestHandlerService during configuration.

 public class HRRequestHandlerService : DefaultRequestHandlerService<HRDbContext>
 {
     public HRRequestHandlerService(HRDbContext context) : base(context)
     {
     }

     public override Task Delete<TEntity>(object[] keyValues, CancellationToken cancellationToken = default)
     {
         throw new InvalidOperationException("Data deletion not allowed.");
     }
 }

(back to top)

Roadmap

  • Dynamic OData Controllers and EDM Model
  • Ability to inject custom code to handle OData requests

See the open issues for a full list of proposed features (and known issues).

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

Contact

Mateusz Radny - mateuszradnywrz@gmail.com

Project Link: https://github.com/mateuszradny/Hermsoft.EntityFrameworkCore.DynamicOData

(back to top)

Acknowledgments

(back to top)

About

Automatic OData v4 API based on EF Core configuration.

License:Apache License 2.0


Languages

Language:C# 99.0%Language:Dockerfile 1.0%