Base solution for your next web application
Open Closed

using SettingManager #1084


User avatar
0
omital created

Hi, AzmaSettings declared in Core project and use it in PreInitialize method of CoreModule. I want to read/write setting from/to db. with this code

public class AzmaSettings : SettingProvider
    {
        private readonly IRepository<ACC.Formals.Formal> _formalRepo;

        public AzmaSettings(IRepository<ACC.Formals.Formal> formalRepo)
        {
            _formalRepo = formalRepo;
        }
        public override IEnumerable<SettingDefinition> GetSettingDefinitions(SettingDefinitionProviderContext context)
        {
            var v = _formalRepo.GetAll().FirstOrDefault().Name;

            return new[]
                {
                    new SettingDefinition(
                        "TestSetting",
                       v
                        )
                };

        }
    }

I got this error

The operation cannot be completed because the DbContext has been disposed.

where is the problem?


3 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Use [UnitOfWork] property when you use GetAll() method. See document: <a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Unit-Of-Work#DocRepositoryGetAll">http://www.aspnetboilerplate.com/Pages/ ... toryGetAll</a>

  • User Avatar
    0
    omital created

    Thank for your response. using [UnitOfWork] solve my problem, but setting manager is not so clear for me. do you have any sample project about manipulate setting for different user and tenant? does setting must be declared in core project and register in core module?

  • User Avatar
    0
    hikalkan created
    Support Team

    If this setting is related to domain, it should be in core/domain layer. I generally define and register settings in core project. setting management documentation should be enough. if not, eventcloud application use it for example (<a class="postlink" href="https://github.com/aspnetboilerplate/eventcloud/blob/master/src/EventCloud.Core/Configuration/EventCloudSettingProvider.cs">https://github.com/aspnetboilerplate/ev ... rovider.cs</a>).