Created
February 28, 2013 15:57
-
-
Save JasonMore/5057770 to your computer and use it in GitHub Desktop.
Session<T> with/without Repository
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IPersonService | |
{ | |
PersonViewModel GetPersonViewModel(int id); | |
} | |
public class PersonService : IPersonService | |
{ | |
ISession _session; | |
public PersonService(ISession session) | |
{ | |
_session = session; | |
} | |
public PersonViewModel GetPersonViewModel(int id) | |
{ | |
var person = _session.Single<Person>(x=>x.Id == id); | |
return new PersonViewModel | |
{ | |
Id = person.Id, | |
FirstName = person.FirstName, | |
LastName = person.LastName | |
}; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IPersonRespository | |
{ | |
Person GetPersonById(int id); | |
} | |
public class PersonRepository : IPersonRespository | |
{ | |
ISession _session; | |
public PersonRepository(ISession session) | |
{ | |
_session = session; | |
} | |
Person GetPersonById(int id) | |
{ | |
return _session.Single<Person>(x => x.Id == id); | |
} | |
} | |
public interface IPersonService | |
{ | |
PersonViewModel GetPersonViewModel(int id); | |
} | |
public class PersonService : IPersonService | |
{ | |
IPersonRespository _personRepository; | |
public PersonService(IPersonRespository personRepository) | |
{ | |
_personRepository = personRepository; | |
} | |
public PersonViewModel GetPersonViewModel(int id) | |
{ | |
var person = _personRepository.GetPersonById(id); | |
return new PersonViewModel | |
{ | |
Id = person.Id, | |
FirstName = person.FirstName, | |
LastName = person.LastName | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment