Open Closed

Database driven Features List #10485

james.marley created


I am trying to setup a dynamic list of features based on rows in a database table. I know I can add in features through code as documented but I haven't found any examples where I can query a table and populate a list of features. My attempts at reading items from a repository have resulted in issues around sync and async on application start up.

I wanted to check that what I'm trying to do is possible/correct and if there is any guidance availabe on how to do this.


1 Answer(s)
  • 0
    musa.demir created
    Support Team

    Hello @james.marley

    You can follow that document to see how to define your features:

    To get datas from database you can simply inject your feature store and list items. For example:

    public class AppFeatureProvider : FeatureProvider
    	private readonly IRepository<MyFeature> _myFeatureRepository;
    	private readonly IUnitOfWorkManager _unitOfWorkManager;
    	public AppFeatureProvider(IRepository<MyFeature> myFeatureRepository, IUnitOfWorkManager unitOfWorkManager)
    		_myFeatureRepository = myFeatureRepository;
    		_unitOfWorkManager = unitOfWorkManager;
    	public override void SetFeatures(IFeatureDefinitionContext context)
    		using (_unitOfWorkManager.Begin())
    			var myFeatures = _myFeatureRepository.GetAll().ToList();
    			foreach (var myFeature in myFeatures){
    				var chatFeature = context.Create(
    					defaultValue: myFeature.defaultValue,
    					displayName: myFeature.displayName,
    					inputType: GetInputTypeOfFeature(myFeature)
    	private IInputType GetInputTypeOfFeature(MyFeature feature){
    		//get input type name from db and cast it to IInputType you want
    			return new SingleLineStringInputType(new NumericValueValidator(0, int.MaxValue));
    		return new CheckboxInputType();