Guest User

Untitled

a guest
Feb 20th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. public class EmailAccessor : IEmailAccessor
  2. {
  3. private string senderEmail;
  4. private string senderUsername;
  5. private string senderPassword;
  6. private int port;
  7.  
  8. public EmailAccessor(string senderEmail, string senderUsername, string senderPassword, int port)
  9. {
  10. this.senderEmail = senderEmail;
  11. this.senderUsername = senderUsername;
  12. this.senderPassword = senderPassword;
  13. this.port = port;
  14. }
  15. //...
  16. }
  17.  
  18. public class NotificationEngine : INotificationEngine
  19. {
  20. private IEmailAccessor emailAccessor;
  21.  
  22. public NotificationEngine(IEmailAccessor emailAccessor)
  23. {
  24. this.emailAccessor = emailAccessor;
  25. }
  26. //...
  27. }
  28.  
  29. [RoutePrefix("api/email")]
  30. public class EmailController : ApiController
  31. {
  32. private INotificationEngine notificationEngine;
  33.  
  34. public EmailController(INotificationEngine notificationEngine)
  35. {
  36. this.notificationEngine = notificationEngine;
  37. }
  38.  
  39. [HttpPost]
  40. [Route("send")]
  41. public void Post([FromBody] EmailNotification email)
  42. {
  43. //...
  44. }
  45. //...
  46. }
  47.  
  48. public static class UnityConfig
  49. {
  50. public static void RegisterTypes(IUnityContainer container)
  51. {
  52. container.LoadConfiguration();
  53.  
  54. //...
  55.  
  56. container.RegisterType<IEmailAccessor, EmailAccessor>(new InjectionConstructor(
  57. ConfigurationManager.AppSettings["SenderEmail"],
  58. ConfigurationManager.AppSettings["SenderUsername"],
  59. ConfigurationManager.AppSettings["SenderPassword"],
  60. int.Parse(ConfigurationManager.AppSettings["Port"])));
  61. container.RegisterType<INotificationEngine, NotificationEngine>();
  62.  
  63. DependencyResolver.SetResolver(new UnityDependencyResolver(container));
  64.  
  65. }
  66. }
  67.  
  68. {
  69. "Message": "No HTTP resource was found that matches the request URI 'http://localhost:63855/api/email/send'.",
  70. "MessageDetail": "No type was found that matches the controller named 'email'."
  71. }
Add Comment
Please, Sign In to add comment