Created
June 23, 2011 10:38
-
-
Save aidanmorgan/1042323 to your computer and use it in GitHub Desktop.
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 class ServiceAwareController : Controller | |
{ | |
private readonly IServiceFactory _serviceFactory; | |
public IAchievementService AchievementService | |
{ | |
get { return _serviceFactory.CreateAchivementService(ServiceContext.Create(User)); } | |
} | |
public IDistilleryService DistilleryService | |
{ | |
get { return _serviceFactory.CreateDistilleryService(ServiceContext.Create(User)); } | |
} | |
public IRatingService RatingService | |
{ | |
get { return _serviceFactory.CreateRatingService(ServiceContext.Create(User)); } | |
} | |
public IRecommendationService RecommendationService | |
{ | |
get { return _serviceFactory.CreateRecommendationService(ServiceContext.Create(User)); } | |
} | |
public IRegionService RegionService | |
{ | |
get { return _serviceFactory.CreateRegionService(ServiceContext.Create(User)); } | |
} | |
public IUserService UserService | |
{ | |
get { return _serviceFactory.CreateUserService(ServiceContext.Create(User)); } | |
} | |
public IWhiskeyService WhiskeyService | |
{ | |
get { return _serviceFactory.CreateWhiskeyService(ServiceContext.Create(User)); } | |
} | |
public IWhiskeyTypeService WhiskeyTypeService | |
{ | |
get { return _serviceFactory.CreateWhiskeyTypeService(ServiceContext.Create(User)); } | |
} | |
public UserDTO GetLoggedInUser() | |
{ | |
if (User.Identity.IsAuthenticated) | |
{ | |
return UserService.FindUserByDisplayName(User.Identity.Name); | |
} | |
throw new InvalidOperationException("Cannot attempt to retrieve the logged in user when the IPrincipal is not authenticated."); | |
} | |
public ServiceAwareController(IServiceFactory factory) | |
{ | |
_serviceFactory = factory; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment