feat(UriBuilderResolver): add to be able to dependencies.
- add UriBuilderFactory confoguration - inejct UriBuilderResolver as transient
This commit is contained in:
parent
bdc773d8ed
commit
91679180ec
@ -1,4 +1,5 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using WorkFlow.Application.Mapping;
|
||||||
|
|
||||||
namespace WorkFlow.Application;
|
namespace WorkFlow.Application;
|
||||||
|
|
||||||
@ -16,11 +17,16 @@ public static class DependencyInjection
|
|||||||
cfg.LicenseKey = diOptions.MediatRLicense;
|
cfg.LicenseKey = diOptions.MediatRLicense;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
services.AddSingleton(diOptions.UriBuilderFactory());
|
||||||
|
services.AddTransient<UriBuilderResolver>();
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class WorkFlowServiceOptions
|
public class WorkFlowServiceOptions
|
||||||
{
|
{
|
||||||
public string MediatRLicense { get; set; } = string.Empty;
|
public string MediatRLicense { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public Func<UriBuilder> UriBuilderFactory { get; set; } = () => new UriBuilder();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,40 +1,34 @@
|
|||||||
using System.Web;
|
using WorkFlow.Application.Buttons;
|
||||||
using WorkFlow.Application.Buttons;
|
|
||||||
using WorkFlow.Application.Dto;
|
using WorkFlow.Application.Dto;
|
||||||
using WorkFlow.Domain.Entities;
|
using WorkFlow.Domain.Entities;
|
||||||
|
|
||||||
namespace WorkFlow.Application;
|
namespace WorkFlow.Application.Mapping;
|
||||||
|
|
||||||
public class MappingProfile : AutoMapper.Profile
|
public class MappingProfile : AutoMapper.Profile
|
||||||
{
|
{
|
||||||
public MappingProfile()
|
public MappingProfile()
|
||||||
{
|
{
|
||||||
// Mapping entity to DTO
|
|
||||||
CreateMap<Config, ConfigDto>();
|
CreateMap<Config, ConfigDto>();
|
||||||
|
|
||||||
CreateMap<Profile, ProfileDto>();
|
CreateMap<Profile, ProfileDto>();
|
||||||
|
|
||||||
CreateMap<PControlsTF, PControlsTFDto>();
|
CreateMap<PControlsTF, PControlsTFDto>();
|
||||||
|
|
||||||
CreateMap<Button, ButtonDto>();
|
CreateMap<Button, ButtonDto>();
|
||||||
|
|
||||||
CreateMap<PObject, ObjectDto>()
|
CreateMap<PObject, ObjectDto>()
|
||||||
.ForMember(dest => dest.Headlines, opt => opt.MapFrom(src => new[] { src.Headline1, src.Headline2 }))
|
.ForMember(dest => dest.Headlines, opt => opt.MapFrom(src => new[] { src.Headline1, src.Headline2 }))
|
||||||
.ForMember(dest => dest.Sublines, opt => opt.MapFrom(src => new[] { src.Subline1, src.Subline2 }));
|
.ForMember(dest => dest.Sublines, opt => opt.MapFrom(src => new[] { src.Subline1, src.Subline2 }));
|
||||||
|
|
||||||
CreateMap<PObjectState, ObjectStateDto>()
|
CreateMap<PObjectState, ObjectStateDto>()
|
||||||
.ForMember(dest => dest.Intl, opt => opt.MapFrom(src => src.State1 != null ? src.State1.IntlState : null))
|
.ForMember(dest => dest.Intl, opt => opt.MapFrom(src => src.State1 != null ? src.State1.IntlState : null))
|
||||||
.ForMember(dest => dest.Others, opt => opt.MapFrom(src => new string?[] { src.State2, src.State3, src.State4 }));
|
.ForMember(dest => dest.Others, opt => opt.MapFrom(src => new string?[] { src.State2, src.State3, src.State4 }));
|
||||||
|
|
||||||
CreateMap<PObjectStateHist, ObjectStateHistDto>()
|
CreateMap<PObjectStateHist, ObjectStateHistDto>()
|
||||||
.ForMember(dest => dest.Intl, opt => opt.MapFrom(src => src.State1 != null ? src.State1.IntlState : null))
|
.ForMember(dest => dest.Intl, opt => opt.MapFrom(src => src.State1 != null ? src.State1.IntlState : null))
|
||||||
.ForMember(dest => dest.Others, opt => opt.MapFrom(src => new string?[] { src.State2, src.State3, src.State4 }));
|
.ForMember(dest => dest.Others, opt => opt.MapFrom(src => new string?[] { src.State2, src.State3, src.State4 }));
|
||||||
|
|
||||||
CreateMap<TfFile, TfFileDto>()
|
CreateMap<TfFile, TfFileDto>()
|
||||||
.ForMember(dest => dest.Url, opt => opt.MapFrom(src => UriBuilder.WithPath(src.Path, true)));
|
.ForMember(dest => dest.Url, opt => opt.MapFrom<UriBuilderResolver>());
|
||||||
}
|
|
||||||
|
|
||||||
public static UriBuilder UriBuilder { get; set; } = new UriBuilder();
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static class HttpUtilityExtensions
|
|
||||||
{
|
|
||||||
public static UriBuilder WithPath(this UriBuilder builder, string path, bool encode = true)
|
|
||||||
{
|
|
||||||
builder.Path = encode ? HttpUtility.UrlEncode(path) : path;
|
|
||||||
return builder;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
22
src/WorkFlow.Application/Mapping/UriBuilderResolver.cs
Normal file
22
src/WorkFlow.Application/Mapping/UriBuilderResolver.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using System.Web;
|
||||||
|
using WorkFlow.Application.Dto;
|
||||||
|
using WorkFlow.Domain.Entities;
|
||||||
|
|
||||||
|
namespace WorkFlow.Application.Mapping;
|
||||||
|
|
||||||
|
public class UriBuilderResolver : IValueResolver<TfFile, TfFileDto, UriBuilder>
|
||||||
|
{
|
||||||
|
private readonly UriBuilder _uriBuilder;
|
||||||
|
|
||||||
|
public UriBuilderResolver(UriBuilder uriBuilder) => _uriBuilder = uriBuilder;
|
||||||
|
|
||||||
|
public UriBuilder Resolve(TfFile source, TfFileDto destination, UriBuilder destMember, ResolutionContext context)
|
||||||
|
{
|
||||||
|
var builder = new UriBuilder(_uriBuilder.Uri)
|
||||||
|
{
|
||||||
|
Path = HttpUtility.UrlEncode(source.Path)
|
||||||
|
};
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user