Created
May 16, 2012 15:45
-
-
Save jmcd/2711457 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 OrganisationProfile : Profile | |
{ | |
protected override void Configure() | |
{ | |
CreateMap<Organisation, OrganisationIndex.Item>() | |
.ForMember(dest => dest.EditUrl, opt => opt.ResolveUrl().WithAction<OrganisationController>(src => c => c.Update(src.Id))); | |
} | |
} |
This file contains hidden or 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 static class ResolveUrlExtension | |
{ | |
public static MemberConfigurationExpressionWrapper<TSource> ResolveUrl<TSource>(this IMemberConfigurationExpression<TSource> opt) | |
{ | |
return new MemberConfigurationExpressionWrapper<TSource>(opt); | |
} | |
public class MemberConfigurationExpressionWrapper<TSource> | |
{ | |
private readonly IMemberConfigurationExpression<TSource> _opt; | |
public MemberConfigurationExpressionWrapper(IMemberConfigurationExpression<TSource> opt) | |
{ | |
_opt = opt; | |
} | |
public IResolverConfigurationExpression<TSource, UrlResolver<TController>> WithAction<TController>(Func<TSource, Expression<Action<TController>>> sourceMember) where TController : Controller | |
{ | |
return _opt.ResolveUsing<UrlResolver<TController>>().FromMember(sourceMember); | |
} | |
} | |
} |
This file contains hidden or 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 UrlResolver<TController> : ValueResolver<Expression<Action<TController>>, string> where TController : Controller | |
{ | |
private readonly IUrls _urls; | |
public UrlResolver(IUrls urls) | |
{ | |
_urls = urls; | |
} | |
protected override string ResolveCore(Expression<Action<TController>> source) | |
{ | |
return _urls.Action(source); | |
} | |
} |
This file contains hidden or 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 IUrls | |
{ | |
string Action<TController>(Expression<Action<TController>> action) where TController : Controller; | |
} | |
public class Urls : IUrls | |
{ | |
private readonly RequestContext _requestContext; | |
public Urls(RequestContext requestContext) | |
{ | |
_requestContext = requestContext; | |
} | |
public string Action<TController>(Expression<Action<TController>> action) where TController : Controller | |
{ | |
return LinkBuilder.BuildAreaUrlFromExpression(_requestContext, RouteTable.Routes, action); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment