Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create UOW middleware for AspNet Core #2563

Closed
hikalkan opened this issue Oct 3, 2017 · 0 comments
Closed

Create UOW middleware for AspNet Core #2563

hikalkan opened this issue Oct 3, 2017 · 0 comments
Assignees
Labels
Milestone

Comments

@hikalkan
Copy link
Member

hikalkan commented Oct 3, 2017

This will make possible to be able to use dbconnection after action execution (for returning IQueryable from controller for 3rd party UI libraries or for making lazy loading available in razor views too).

How to use

Add UseUnitOfWork in the Configure method of your Startup file

public void Configure(IApplicationBuilder app)
{
    app.UseAbp();
   
    //...other middlewares

    app.UseUnitOfWork(); //Add before UseMvc

    app.UseMvc(...);
}

Side effects

If you use UOW middleware;

  • All your requests will create a UOW even it's not needed.
  • [UnitOfWork(isTransactional=false)] and similar declerations will not work for controller actions since UOW has already began before the action.

To overcome this potential problems, we suggest you to only use UOW middleware for specific case when you need to an open database connection after MVC action complete. You can configure UseUnitOfWork like that:

app.UseUnitOfWork(options =>
{
    options.Filter = httpContext =>
    {
        //...return true or false to filter request based on URL or other HttpContext properties
    };
});

Finally, you can set options.OptionsFactory to control unit of work options (like transactional or not).

@hikalkan hikalkan added this to the v3.2 milestone Oct 3, 2017
@hikalkan hikalkan self-assigned this Nov 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant