Hello,
I am injecting in my services a global Settings interface, as Singleton, using StructureMap:
public interface ISettings {
LoggerSettings Logger { get; }
} // ISettings
public class LoggerSettings {
public String Levels { get { return ConfigurationManager.AppSettings["Logger.Levels"]; } }
public const String Report = "te...@xyz.com";
} // LoggerSettings
public class Settings : ISettings {
public LoggerSettings Logger { get; private set; }
} // Settings
And as SM configuration I have:
For<ISettings>().Singleton().Use<Settings>();
I am able to inject this object but when I check the injected object its property Logger is null ... How can I have SM to initialize the object properties?
Am I missing something?
Thank you,This is still relevant to StructureMap 2.6 (and 3 for that matter): It wouldn't help you even it was injected because it gets involved before the behavior is pulled from the container.StructureMap does not do setter injection automatically. You'll have to explicitly enable setter injection, but in this case it won't work for you because the setter in question is private.Honestly? If I were you I'd just inject LoggerSettings directly as a singleton and not worry about anything else.Jeremy D. Miller
From: Shapper
To: structure...@googlegroups.com
Sent: Wed, March 27, 2013 8:19:14 PM
Subject: [sm-users] Initialize Object Properties
--Hello,
I am injecting in my services a global Settings interface, as Singleton, using StructureMap:
public interface ISettings { LoggerSettings Logger { get; } } // ISettings public class LoggerSettings { public String Levels { get { return ConfigurationManager.AppSettings["Logger.Levels"]; } } public const String Report = "te...@xyz.com"; } // LoggerSettings public class Settings : ISettings { public LoggerSettings Logger { get; private set; } } // SettingsAnd as SM configuration I have:
For<ISettings>().Singleton().Use<Settings>();I am able to inject this object but when I check the injected object its property Logger is null ... How can I have SM to initialize the object properties?
Am I missing something?
Thank you,
Miguel
You received this message because you are subscribed to the Google Groups "structuremap-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to structuremap-users+unsub...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to structuremap-us...@googlegroups.com.
To post to this group, send email to structure...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/structuremap-users/-/ejnsjVyFmCoJ.