![Logo](https://raw.githubusercontent.com/mateuszradny/Hermsoft.EntityFrameworkCore.DynamicOData/main/images/logo.png)
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
Library created as part of the (https://100commitow.com) competition
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.
This is an example of how to list things you need to use the software and how to install them.
- .NET Core 9.0
dotnet add package Hermsoft.EntityFrameworkCore.DynamicOData
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
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.");
}
}
- 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).
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!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE.txt
for more information.
Mateusz Radny - mateuszradnywrz@gmail.com
Project Link: https://github.com/mateuszradny/Hermsoft.EntityFrameworkCore.DynamicOData