Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Oct 06, 2011 10:17 AM by dvsspr
Member
73 Points
43 Posts
Oct 06, 2011 10:17 AM|LINK
Hello,
I am very curious about how to perform lazy constructor injection using StructureMap 2.6.3.
// Snippet 1 public class AccountController : SpicyController, IAccountController { IVisitorAccountService visitorAccountService; IMemberAccountService memberAccountService; IVisitorAccountService visitor { get { if (visitor == null) { visitorAccountService = ObjectFactory.GetInstance<IVisitorAccountService>(); } return visitorAccountService; } } IMemberAccountService member { get { if (visitor == null) { memberAccountService = ObjectFactory.GetInstance<IMemberAccountService>(); } return memberAccountService; } } // etc... } // Snippet 2 public class AccountController : SpicyController, IAccountController { readonly IVisitorAccountService visitor; readonly IMemberAccountService member; public AccountController(IVisitorAccountService visitorAccountService, IMemberAccountService memberAccountService) { this.visitor = visitorAccountService; this.member = memberAccountService; } // etc... }
I want to be able to do something like Snippet 1 but using constructor injection (like in Snippet 2).
Note: I use C# 4.
dvsspr
Member
73 Points
43 Posts
Lazy constructor injection using StructureMap 2.6.3
Oct 06, 2011 10:17 AM|LINK
Hello,
I am very curious about how to perform lazy constructor injection using StructureMap 2.6.3.
// Snippet 1 public class AccountController : SpicyController, IAccountController { IVisitorAccountService visitorAccountService; IMemberAccountService memberAccountService; IVisitorAccountService visitor { get { if (visitor == null) { visitorAccountService = ObjectFactory.GetInstance<IVisitorAccountService>(); } return visitorAccountService; } } IMemberAccountService member { get { if (visitor == null) { memberAccountService = ObjectFactory.GetInstance<IMemberAccountService>(); } return memberAccountService; } } // etc... } // Snippet 2 public class AccountController : SpicyController, IAccountController { readonly IVisitorAccountService visitor; readonly IMemberAccountService member; public AccountController(IVisitorAccountService visitorAccountService, IMemberAccountService memberAccountService) { this.visitor = visitorAccountService; this.member = memberAccountService; } // etc... }I want to be able to do something like Snippet 1 but using constructor injection (like in Snippet 2).
Note: I use C# 4.