Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static class UnityConfig
- {
- public static void RegisterComponents()
- {
- var container = new UnityContainer();
- // register all your components with the container here
- // it is NOT necessary to register your controllers
- // e.g. container.RegisterType<ITestService, TestService>();
- container.RegisterType<IImage, Image>();
- DependencyResolver.SetResolver(new UnityDependencyResolver(container));
- var _image1 = container.Resolve<IImage>();
- }
- public class MyImage
- {
- public int ID { get; set; }
- public byte[] Image { get; set; }
- }
- public interface IImage
- {
- void GetImage();
- }
- public class Image : IImage
- {
- public byte[] image
- {
- get;
- set;
- }
- public void GetImage()
- {
- using (var ms = new MemoryStream())
- {
- FileStream fs = new FileStream(@"c:usersamiraabdoulisourcereposTestDITestDIContent510222832.jpg", FileMode.Open, FileAccess.Read);
- BinaryReader br = new BinaryReader(fs);
- this.image = br.ReadBytes((int)fs.Length);
- }
- }
- }
- public class Test1Controller : Controller
- {
- private IImage _image1;
- public Test1Controller(IImage im)
- {
- _image1 = im;
- }
- // GET: Test1
- public ActionResult Index()
- {
- _image1.GetImage();
- return View();
- }
Add Comment
Please, Sign In to add comment