for application i'm trying write configuration controller, load , save settings modules. going use ini file, section names represent module names (or other identification), , values represented key.
i registered controller in bootstrapper, , use interface in constructor injection in appropriate classes. not want enter module name every time need or set value, tried use caller info find out module (or class) calling method, apparently not work (return empty string).
is there way achieve i'm trying do?
bootstrapper:
protected override void configurecontainer() { base.configurecontainer(); container.registertype<iconfig, configcontroller>(new containercontrolledlifetimemanager()); }
config interface:
public interface iconfig { string[] getsettings(string caller = ""); void set<t>(string setting, t value, string caller = "") t : class; t get<t>(string setting, string caller = "") t : class; }
the use of caller argument error prone. have many options avoid it:
register configcontroller each module. unity supports multiple named registration. can inject right controller in each module in module initialization, or
dependency
attribute:container.register<iconfig, configcontroller>("module1", new injectionconstructor("module1")) .register<iconfig, configcontroller>("module2", new injectionconstructor("module2")); class module1 { public module1([dependency("module1")] iconfig config) {... } }
define , implement iconfigfactory returns configured iconfig implementation.
interface iconfigfactory { iconfig create(string modulename); }
the configcontroller identify module detecting method made call.
Comments
Post a Comment