jonpsmith / efcore.genericbizrunner Goto Github PK
View Code? Open in Web Editor NEWLibrary to run business logic when using Entity Framework Core for database accesses
License: MIT License
Library to run business logic when using Entity Framework Core for database accesses
License: MIT License
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
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.
How would you go about using this in production without support for cancellation tokens?
Hello,
I want to achieve two things in my WebAPI project:
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
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
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.
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.
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);
Hi,
Wiki page Unit and integration testing has a dead link; "Have a look at this unit test as an example." on the top of the page, I assume it should point to this example.
It is a pity one cannot make PR for Wiki pages in GitHub, I would rather provide a PR than raising an issue.
Cheers
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?
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!
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
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.
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.