I'm not sure how to ask this, but I want to create a new object in a linq statement, and initialize it's values. Since I have to use StructureMap's GetInstance method to get an instance of the object, I don't think this is possible. Am I wrong? And before we get off-topic, I realize I could probably create a constructor that takes the values I want to use, but I want to know if there's any way that I can do it with initializers and structuremap. I'm really weak on structuremap, and for all I know, there may be a simple way I'm just missing...
Thanks for any thoughts.
//basically, I'm creating a new object when I don't have an existing one for the groupid //conceptually, this is adding users to the selected groups if they don't already belong from g in GroupIDs where !OriginalGroups.Exists(ug => ug.SecurityGroupID == g) select StructureMap.ObjectFactory.GetInstance() {//initialize values of usertosecuritygroup};
//this is how I would do it if I wasn't relying on DI. from g in GroupIDs where !OriginalGroups.Exists(ug => ug.SecurityGroupID == g) select new UserToGroup {UserID = UserID, GroupID = g};