次のコードがあります
SmtpSection smtpsection =
(SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp");
EmailSettings emailSettings = new EmailSettings
{
WriteAsFile = bool.Parse(ConfigurationManager.AppSettings[""] ?? "false"),
ServerPort = smtpsection.Network.Port,
Username = smtpsection.Network.UserName,
Password = smtpsection.Network.Password,
UseSsl = smtpsection.Network.EnableSsl
};
kernel.Bind<IEmailRepository>().To<EmailRepository>().WithConstructorArgument("settings", emailSettings);
と
public class EmailSettings
{
public string MailToAddress = "test@Test.com";
public string MailFromAddress = "test@test.com";
public bool UseSsl = true;
public string Username = "";
public string Password = "";
public string ServerName = "";
public int ServerPort = 587;
public bool WriteAsFile = false;
public string FileLocation = @"C:\sports_store_emails";
}
public class EmailController : Controller
{
private IEmailRepository emailRepository;
private EmailSettings emailSettings;
public EmailController(IEmailRepository emailRepository, EmailSettings settings)
{
this.emailRepository = emailRepository;
this.emailSettings = settings;
}
}
public class EmailRepository : RepositoryBase<EmailEnquiry>, IEmailRepository
{
public EmailRepository(IDatabaseFactory databaseFactory)
: base(databaseFactory)
{
}
}
public interface IEmailRepository : IRepository<EmailEnquiry>
{
}
public interface IRepository<T> where T : class
{
void Add(T entity);
void Update(T entity);
void Delete(T entity);
void Delete(Expression<Func<T, bool>> where);
T GetById(long Id);
T GetById(string Id);
T Get(Expression<Func<T, bool>> where);
IEnumerable<T> GetAll();
IEnumerable<T> GetMany(Expression<Func<T, bool>> where);
IQueryable<T> SearchFor(Expression<Func<T, bool>> predicate);
}
何らかの理由で、NInject の引数が設定に渡されません。これがなぜなのか、誰にもわかりません。EmailSettings
設定は、NInject から渡されたものではなく、内部からのすべての値を使用していますか?