简体   繁体   中英

Ninject WithConstructorArgument to Simple Injector Implementation

What is the direct implementation from Ninject's WithConstructorArgument to a Simple Injector implementation?

 var emailTemplates = new EmailTemplates
 {
      MasterPageTemplate = MVC.Email.Views._Layout
 };

 container.Register<IEmailService, EmailService>()
     .WithConstructorArgument("templates", emailTemplates);

Class

public EmailTemplatesService(
            EmailTemplates templates,
            IEventEmailTemplatesRepository eventEmailTemplatesRepository)

In Simple Injector, you can do this:

container.Register<IEmailService>(() => new EmailService(
    emailTemplates,
    container.GetInstance<IEventEmailTemplatesRepository>()));

Or you can do this:

// Wrap the string value into a DTO and inject that
public EmailService(
    EmailServiceSettings settings, IEventEmailTemplatesRepository r) { ... }

container.RegisterInstance(new EmailServiceSettings(emailTemplates));
container.Register<IEmailService, EmailService>();

Or you can override the parameter injection behavior, as explained here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM