Git Product home page Git Product logo

Comments (5)

cbrianball avatar cbrianball commented on May 18, 2024 4

I ran into this issue yesterday. I managed to code around it, but it was less than ideal.

I ran into two primary issues:

  1. I inject the current user via an interface I've created.
  2. I was unable to inject my EF Core database context (and even if I could, there could be potential issues as EF Core DB Context is not meant to be run on multiple threads).

For the first issue, a web project could inject IHttpContextAccessor, but my code is in a shared library that is used by both a web project and non-web projects. I worked around this by creating a type that functions similarly to HttpContextAccessor, but for my interface that describes the current user instead.

I could have passed the user object into the feature manager method as a context, but then the calling code would need to know that the configured feature filters would need to act on the current user, and I don't believe that's a good idea.

For the second issue, I ended up injecting IServiceProvider into my feature filters that need to access the database. This is a hack, in my opinion, and I hope to find another solution in the near future.

Both of these could have been avoided if the registered feature filters were not singletons (either scoped or transient would have sufficed).

The code-base seems pretty straight forward, but I don't want to make any bad assumptions. If you can give me some general direction (or at least tell me what you are trying to avoid), I can work on a PR to allow feature filters to not necessarily be singleton.

from featuremanagement-dotnet.

jimmyca15 avatar jimmyca15 commented on May 18, 2024

Is this different from existing behavior? I wouldn't expect a scoped service to be able to be used in the feature filters which are singletons. This is why things like IHttpContextAccessor services exist which give a way to access the scoped HttpContext.

from featuremanagement-dotnet.

jimmyca15 avatar jimmyca15 commented on May 18, 2024

Closing since there has been no response. Please re-open if my response is inadequate.

from featuremanagement-dotnet.

szalapski avatar szalapski commented on May 18, 2024

I am hitting this too. I wish it could depend on a scoped ISessionManager.

from featuremanagement-dotnet.

zhiyuanliang-ms avatar zhiyuanliang-ms commented on May 18, 2024

I ran into this issue yesterday. I managed to code around it, but it was less than ideal.

I ran into two primary issues:

  1. I inject the current user via an interface I've created.
  2. I was unable to inject my EF Core database context (and even if I could, there could be potential issues as EF Core DB Context is not meant to be run on multiple threads).

For the first issue, a web project could inject IHttpContextAccessor, but my code is in a shared library that is used by both a web project and non-web projects. I worked around this by creating a type that functions similarly to HttpContextAccessor, but for my interface that describes the current user instead.

I could have passed the user object into the feature manager method as a context, but then the calling code would need to know that the configured feature filters would need to act on the current user, and I don't believe that's a good idea.

For the second issue, I ended up injecting IServiceProvider into my feature filters that need to access the database. This is a hack, in my opinion, and I hope to find another solution in the near future.

Both of these could have been avoided if the registered feature filters were not singletons (either scoped or transient would have sufficed).

The code-base seems pretty straight forward, but I don't want to make any bad assumptions. If you can give me some general direction (or at least tell me what you are trying to avoid), I can work on a PR to allow feature filters to not necessarily be singleton.

This issue should be re-opened. @jimmyca15 @cbrianball @szalapski

from featuremanagement-dotnet.

Related Issues (20)

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.