StructureMap Question

Posted by derans on Stack Overflow See other posts from Stack Overflow or by derans
Published on 2010-02-02T03:42:28Z Indexed on 2010/04/17 10:03 UTC
Read the original article Hit count: 252

Filed under:

This is the equivalent of what I'm trying to create with StructureMap:

new ChangePasswordWithNotificationAndLoggingService(
new ChangePasswordService(
      new ActiveDirectoryRepository(new ActiveDirectoryCredentials()),
      new TokenRepository("")),
new EmailNotificationService(new PasswordChangedNotification(new UserAccount())),
new LoggingService());

This is what I have right now:

ForRequestedType<IChangePasswordService>()
  .TheDefault.Is.ConstructedBy(() => 
     new ChangePasswordService(DependencyRegistrar.Resolve<IActiveDirectoryRepository>(),
                               DependencyRegistrar.Resolve<ITokenRepository>()))
  .EnrichWith<IChangePasswordService>(x => 
     new ChangePasswordWithNotificationAndLoggingService(x,
                   DependencyRegistrar.Resolve<INotificationService>(),
                   DependencyRegistrar.Resolve<ILoggingService>()));

I need to pass the UserAccount to the INotificationService...can't figure it out.

I've tried this: DependencyRegistrar.With(new UserAccount { Username = "test" });

No luck...UserAccount always turns out null. I don't have to do it all with StructureMap, I'm open to any suggestions.

This is what I currently have working:

public static IChangePasswordService ChangePasswordService(UserAccount userAccount)
{
    return new ChangePasswordWithNotificationService(
        new ChangePasswordService(ActiveDirectoryRepository(), TokenRepository()),
        new EmailNotificationService(new PasswordChangedNotification(userAccount)));
}

© Stack Overflow or respective owner

Related posts about structuremap