Skip to content

Instantly share code, notes, and snippets.

@dariuszparzygnat
Created September 21, 2017 20:57
Show Gist options
  • Save dariuszparzygnat/3a0b226061f7e99804f58d119d336a52 to your computer and use it in GitHub Desktop.
Save dariuszparzygnat/3a0b226061f7e99804f58d119d336a52 to your computer and use it in GitHub Desktop.
using System.Collections.Generic;
using System.Linq;
using AutomapperConfiguration.AutoMapperConfig;
using AutoMapper;
namespace AutomapperConfiguration
{
public class PeopleService
{
private readonly IMapper _mapper;
private readonly IEnumerable<Person> _people;
public PeopleService(IEnumerable<Person> people, IAutoMapperConfiguration autoMapperConfiguration)
{
_people = people;
_mapper = autoMapperConfiguration.Configure().CreateMapper();
}
public IList<NewsletterDto> GetPeopleForNewsletter()
{
var peopleAssignedToNewsletter = _people.Where(e => e.AssignedToNewsletter);
var result = _mapper.Map<IEnumerable<Person>, IList<NewsletterDto>>(peopleAssignedToNewsletter);
return result;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment