Base solution for your next web application
Open Closed

Accessing settings from entities and aggregate roots (core project) #9937


User avatar
0
rasoulshams created
  • 9.1
  • Mvc
  • .Net core

I know settings can be accessed from application services, domain services and controllers using base classes or by injecting ISettingManager but how can settings be accessed from within entities and aggregate roots inside the core project? Some of my entities require the settings datas but I can't access them from entities.

I'd appreciate if someone can help.


1 Answer(s)
  • User Avatar
    0
    zony created
    Support Team

    Hi rasoulshams, This is not a good implementation, Normally, domain objects will not inject external dependencies. You can process this part of the logic in DomainService and pass it to the domain objects.

    If you really want to do this, you can use a static instance of IocManager in the entity.

        public class ProductEntity : Entity<int>, ITransientDependency
        {
            public string Name { get; set; }
    
            public string Description { get; set; }
    
            public void Get()
            {
                var settingMgr = IocManager.Instance.Resolve<ISettingManager>();
            }
        }