Skip to content

Instantly share code, notes, and snippets.

@JasonMore
Created February 28, 2013 15:57
Show Gist options
  • Save JasonMore/5057770 to your computer and use it in GitHub Desktop.
Save JasonMore/5057770 to your computer and use it in GitHub Desktop.
Session<T> with/without Repository
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
};
}
}
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