-
Notifications
You must be signed in to change notification settings - Fork 120
Add getting features from database example #389
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
base: main
Are you sure you want to change the base?
Add getting features from database example #389
Conversation
@microsoft-github-policy-service agree |
/AzurePipeline run |
Azure Pipelines successfully started running 1 pipeline(s). |
builder.Services.AddFeatureService(); | ||
|
||
/* Add feature management */ | ||
builder.Services.AddScoped<IFeatureDefinitionProvider, CustomFeatureDefinitionProvider>().AddScopedFeatureManagement(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, @fffffatah Maybe this is a stupid question. Would you mind explaining why CustomFeatureDefinitionProvider is registered as scoped here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @zhiyuanliang-ms 👋, CustomFeatureDefinitionProvider is scoped here because the life-time of DbContext and the service which is used to read the features from DB are scoped. If I'm not wrong, setting the life time of DbContext as singleton might lead to issues when many concurrent calls are made. Although, DbContext can be registered as singleton and the Feature set can be marked AsNoTracking while querying, but it felt a bit risky.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
examples/GettingFeaturesFromDatabase/Database/ServiceCollectionExtensions.cs
Show resolved
Hide resolved
@fffffatah When I tried to run this application, it gave the result of "localhost page can not be found". This is quite misleading, which will make user doubt whether there is something wrong. So my suggestion is to add a home page and make this web app more straight forward. Let the user see what you want them to see at the home page. Then, I tried to access localhost:12345/weatherforecast. It gave me the following error: And I tried to remove the FeatureGate above the get method of controller, it works. I guess the previous exception is because there is no database. Would you mind including a README? (something like: example 1 example 2) The README should introduce this example application and teach users how to run it. |
@zhiyuanliang-ms I simplified the example for initial run and added Swagger UI for ease of use. Also, added a README to get started. Sorry about the exception, it happened due to a package mismatch. |
/AzurePipeline run |
Azure Pipelines successfully started running 1 pipeline(s). |
@fffffatah The application works for me now. But It seems like the CI pipeline failed. I will take some time to look into it. Thank you for your interest and support for this repo. Appreciate you spending the time on this PR. This PR fills a missing piece of examples in this repo. We provides the IFeatureDefinitionProvider interface and this interface provides the extensibility to allow users to implement their own feature definition provider. But we don't have any detailed tutorial or example about how to implement IFeatureDefinitionProvider, which was called out 3 years ago. (Previous issue can be found in #93) This PR also lets us know how actually user will use our FM lib to work with feature flags from database. The use case of importing feature flag from database is common especially when users are migrating from other third-party feature management libs. This is super valuable for us. Really appreciate that. So even if this PR cannot be merged, it brings a good chance for us to seriously consider how to build an example app of implementing a custom feature defintion provider from a database. Another interesting thing is that this PR uses the Thanks again for your effort. @fffffatah This PR is super valuable for us. |
@zhiyuanliang-ms Looks like BinSkim is having trouble with native SQLite binary as it doesn't have a |
I guess Even if a PR can not pass the pipeline check, it still can be merged. So, don't be too worried about it. Comparing to SQL server, I think SQLite may be a better choice, because it is lighter and user can use it directly as long as the nuget package is installed. |
Simple example for getting features from a database. Example includes,