c# - Creating a new instance of a class outside constructor with Dependency Injection -


i trying sample application test out dependency injection. before using di, have following method in class:

public iqueryable<bookdto> getbooks() {     var books = b in db.books                 select new bookdto()                 {                     id = b.id,                     title = b.title,                     authorname = b.author.name                 };      return books; } 

bookdto data transfer object defined in project. want loosely couple projects together. created idtobase interface , made bookdto implement this. have unity container have made relevant registering of bookdto class idtobase.

but how rewrite linq query in original method? take place of "new bookdto()"?

thanks

you start off part of answer think: 'bookdto data transfer object'. such there little value in abstracting belongs in specific layer of application.

the bookdto has role of being purely data representation of book (in presumably serializable form). occur @ low level in application stack. code requires use of such data should create domain object 'book' can used in code. decouples persistence , retrieval of book data (bookdto) it's domain representation (book).

your interface definition don't think serves purpose , di doesn't serve purpose here. feel di comes play here in retrieval of book dtos. class loads book data have such service injected , use retrieve bookdto instances.


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -