Guest User

Untitled

a guest
Jun 20th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. public static class UnityConfig
  2. {
  3. public static void RegisterComponents()
  4. {
  5. var container = new UnityContainer();
  6.  
  7. // register all your components with the container here
  8. // it is NOT necessary to register your controllers
  9.  
  10. // e.g. container.RegisterType<ITestService, TestService>();
  11.  
  12. container.RegisterType<IImage, Image>();
  13.  
  14. DependencyResolver.SetResolver(new UnityDependencyResolver(container));
  15.  
  16. var _image1 = container.Resolve<IImage>();
  17.  
  18.  
  19.  
  20. }
  21.  
  22. public class MyImage
  23. {
  24. public int ID { get; set; }
  25. public byte[] Image { get; set; }
  26.  
  27. }
  28.  
  29.  
  30. public interface IImage
  31. {
  32. void GetImage();
  33. }
  34.  
  35.  
  36.  
  37. public class Image : IImage
  38. {
  39.  
  40. public byte[] image
  41. {
  42. get;
  43. set;
  44. }
  45.  
  46.  
  47.  
  48. public void GetImage()
  49. {
  50. using (var ms = new MemoryStream())
  51. {
  52. FileStream fs = new FileStream(@"c:usersamiraabdoulisourcereposTestDITestDIContent510222832.jpg", FileMode.Open, FileAccess.Read);
  53. BinaryReader br = new BinaryReader(fs);
  54. this.image = br.ReadBytes((int)fs.Length);
  55.  
  56. }
  57. }
  58. }
  59.  
  60. public class Test1Controller : Controller
  61. {
  62. private IImage _image1;
  63.  
  64. public Test1Controller(IImage im)
  65. {
  66. _image1 = im;
  67. }
  68.  
  69. // GET: Test1
  70. public ActionResult Index()
  71. {
  72. _image1.GetImage();
  73. return View();
  74. }
Add Comment
Please, Sign In to add comment