Giter Site home page Giter Site logo

jonpsmith / efcore.genericbizrunner Goto Github PK

View Code? Open in Web Editor NEW
216.0 216.0 58.0 1.77 MB

Library to run business logic when using Entity Framework Core for database accesses

Home Page: http://www.thereformedprogrammer.net/a-library-to-run-your-business-logic-when-using-entity-framework-core/

License: MIT License

C# 90.07% CSS 0.28% JavaScript 3.10% HTML 6.55%

efcore.genericbizrunner's People

Contributors

anapher avatar dependabot[bot] avatar jonpsmith avatar

Stargazers

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

Watchers

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

efcore.genericbizrunner's Issues

Option to use this library with ServiceLifetime.Transient

Hey,

I am currently migrating my project to GraphQl instead of the rest pattern.
Therefore I need to set the service lifetime of the context to ServiceLifetime.Transient. Because in GraphQl each field of the request is called concurrently so that if the lifetime is set to ServiceLifetime.Scoped which will when fail because the same context is used by two different resolvers. Is there a simple workaround to get IActionServiceAsync working with a transient context because else the runner doesn't call SaveChanges() on the correct context instance.

Regards Artur

ArgumentNullException on placing order

Hi,

I just made a new clone, and run the ExampleWebApp, but when I try to place an order, I get a NullReferenceException on the PlaceOrderActions.BizAction method, because the CheckoutLineItems property on the DTO is null.

By the way, your book is great! I think it's the best practical programming related book I ever read.

ActionService mapping to TOut2

Hello,

I want to achieve two things in my WebAPI project:

  1. I want my actions to return data-level entities so that after calling save changes the Primary Keys will be updated (so that they are there before mapping is called)
  2. I want my ActionService to map data-level entity (TOut) to another level model (narrowing down the set of properties when needed).

Is that possible? Either I am missing something or the project only allowes to narrow down the input data before passing it to actions and does not care much about narrowing down the result set––for the WebAPI with Angular I think the latter is more important.

I would appreciate the feedback
Best
Piotr

Database migrations

How do you go about making changes to the database structure (without recreating the whole database)? For example adding a new field to Order entity/table. Is it possible to generate migrations?

I use the ExampleWebApp webapp provided in the repo.

Added a new property called ISBN to Order entity and tried to generate a migration like this:

add-migration Added_ISBN_To_Order -Context OrderDbContext

but got error

Unable to create an object of type 'OrderDbContext'. Add an implementation of 'IDesignTimeDbContextFactory<OrderDbContext>' to the project, or see https://go.microsoft.com/fwlink/?linkid=851728 for additional patterns supported at design time.

I'm especially interested in how this works when there are multiple db contexts (https://github.com/JonPSmith/EfCore.GenericBizRunner/wiki/Using-multiple-DbContexts)

Thanks

Test exception

I downloaded the latest version of your code and ran the tests manually, and they all passed. I was going to have a play with some of the code so turned on Live Tests and this failed:

Test Name: Tests.UnitTests.DDDEntities.TestDddBookLoad.TestLoadBooksOk
Test FullName: Tests.UnitTests.DDDEntities.TestDddBookLoad.TestLoadBooksOk
Test Source: f:\Repos\EfCore.GenericBizRunner\Tests\UnitTests\DDDEntities\TestDddBookLoad.cs : line 16
Test Outcome: Failed
Test Duration: 0:00:00.01

Result StackTrace:
at TestSupport.Helpers.TestData.GetCallingAssemblyTopLevelDir(Assembly callingAssembly)
at Tests.UnitTests.DDDEntities.TestDddBookLoad.TestLoadBooksOk()
Result Message: System.Exception : Did not find '\bin' in the assembly. Do you need to provide the callingAssembly parameter?

Running on VS2019 Preview 3.

Returning the actualt result instead of default(TOut)

Hi,

Thanks for sharing and maintaining this library. I find this library explicitly useful to encapsulate by business logic. On the other side, if find the mechanism of converting the output of the business logic into a useful HTTP response a bit weak. Currently, I'm thinking about in some cases to bypass the feature of the EfCore.GenericService.AspNetCore library to construct my responses, and instead, do it "manually" in the controller.

As this library encapsulates the Business Logic, I want my business logic (Action class) to report the corresponding HttpStatus code beside any textual errors reported by the AddError(string errorMessage, ...) method. At first, in my mind, without any changes in any of the libraries, I thought of returning a Tuple from the Action class where one element would represent the HttpStatusCode to be returned by the controller. But sadly I discovered that the ActionService returns default(TOut) instead of the actual result of the business logic is executed when the bizInstance has errors.

if (bizStatus.HasErrors) return default(TOut);

What will be the arguments and side effects of changing the library to actually return the result of the BizAction, instead of default(TOut) ? Something like this:

//This handles optional call of save changes
SaveChangedIfRequiredAndNoErrors(db, bizStatus);
// if (bizStatus.HasErrors) return default(TOut);

return fromBizCopier.DoCopyFromBiz<TOut>(db, WrappedConfig.FromBizIMapper, result);

Abstracted, dynamic, IActionService.RunBizAction() makes code analysis problematic

When reading through your project I'm noticing that It's difficult to automatically find and identify method usage and to map call trees, as many of the trees (Going up, starting from Controller methods) meet dead ends in calls to dynamic objects. This is partially overcomeable by understanding your library and knowing that you must follow the generic for IActionService, but still completely breaks automatic code analysis right from the get-go.

I'm interested in your project, but the crux of the matter is that this is concerning, and seems like an operational efficiency risk... Without the ability to use the tools provided for .Net code analysis, how can a codebase be effectively mapped, or future developers quickly jump in and understand the call hierarchy?

It's almost feels like a form of crude obfuscation.

This seems like a flaw with this library. What are your thoughts on this?

How to get user-dependent values into view model?

Hi Jon,

trying out EfCore.GenericBizRunner I ran into following challenge:

I have a table with many products owned by different users.
The view should allow users to edit their own products, while others can only be viewed.
An administrator shall be able to edit all products.
I am using ASP.NET Core authentication.

For example. consider your ExampleWebApp and look at Home\\Index.cshtml around line 61:

@foreach (var item in Model.BooksList) { ... }

I'd like to have a property item.CanEditBook which is true for admins and for the author of the current book. How would I do that? Any ideas? Or would you say, that ServiceLayer.BookServices.BookListDto should not contain user-dependent values and the view should generate user-dependent content on its own?

Thanks!

Would running a series of BizLogic with a transaction be useful?

In my previous version of the GenericBizRunner I had a feature that would run a series of business logic methods inside a transaction, e.g.

Start database transaction

  • Run business logic 1
  • Run business logic 2
  • Run business logic 3
  • Commit if all OK, or rollback if any failed

End transaction

See this article for a detailed description of this feature.

I don't know if people would find this feature useful. If you would like it then add a πŸ‘ or πŸ‘Ž to this issue.

Project-based business logic

Hey,
no idea if you can help me with that, but I'm having huge problems adapting this library for my project:
In my application, users can create their own projects and create notes for these projects (as an example). The problem is now that beside the DTO for the note, the business logic needs to know the project id in order to create the note. Actually, the best would be to accept the project id as a second input, but that is not possible with this library. My solution was to use a generic wrapper class ProjectContext<T>, and every DTO must be wrapped using it, but this solution is rather ugly, also because this library is not strongly typed.

I have around 30 business logic classes that require the project id in order to execute their action, I thought about creating something like this:

    public interface IProjectActionAsync<in TIn, TOut> : IBizActionStatus
    {
        Guid ProjectId { get; set; }
        Task<TOut> BizActionAsync(TIn inputData);
    }

    public interface IProjectActionServiceAsync<TContext, TBizInstance>
        where TContext : DbContext where TBizInstance : class
    {
        Task<TOut> RunBizActionAsync<TOut>(object inputData, Guid projectId);
        Task<TOut> RunBizActionAsync<TOut>(Guid projectId);
        Task RunBizActionAsync(object inputData, Guid projectId);
        //...
    }

but I'd have to rewrite your whole library (and project independent business logic wouldn't be possible anymore).
I really liked your book and I'm sure you created something huge here, but I'm still not sure if it fits my needs. How would you handle that?

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.