.NET Core Extensions and Helper NuGet packages. If you are looking for the .NET Boxed project templates, you can find them here.
A simple and fast (fastest?) object to object mapper that does not use reflection. Read A Simple and Fast Object Mapper for more information.
public class MapFrom
{
public bool BooleanFrom { get; set; }
public int IntegerFrom { get; set; }
public List<MapFromChild> ChildrenFrom { get; set; }
}
public class MapFromChild
{
public DateTimeOffset DateTimeOffsetFrom { get; set; }
public string StringFrom { get; set; }
}
public class MapTo
{
public bool BooleanTo { get; set; }
public int IntegerTo { get; set; }
public List<MapToChild> ChildrenTo { get; set; }
}
public class MapToChild
{
public DateTimeOffset DateTimeOffsetTo { get; set; }
public string StringTo { get; set; }
}
public class DemoMapper : IMapper<MapFrom, MapTo>
{
private readonly IMapper<MapFromChild, MapToChild> childMapper;
public DemoMapper(IMapper<MapFromChild, MapToChild> childMapper) => this.childMapper = childMapper;
public void Map(MapFrom source, MapTo destination)
{
destination.BooleanTo = source.BooleanFrom;
destination.IntegerTo = source.IntegerFrom;
destination.ChildrenTo = childMapper.MapList(source.ChildrenFrom);
}
}
public class DemoChildMapper : IMapper<MapFromChild, MapToChild>
{
public void Map(MapFromChild source, MapToChild destination)
{
destination.DateTimeOffsetTo = source.DateTimeOffsetFrom;
destination.StringTo = source.StringFrom;
}
}
public class UsageExample
{
private readonly IMapper<MapFrom, MapTo> mapper = new DemoMapper();
public MapTo MapOneObject(MapFrom source) => this.mapper.Map(source);
public MapTo[] MapArray(List<MapFrom> source) => this.mapper.MapArray(source);
public List<MapTo> MapList(List<MapFrom> source) => this.mapper.MapList(source);
public IAsyncEnumerable<MapTo> MapAsyncEnumerable(IAsyncEnumerable<MapFrom> source) =>
this.mapper.MapEnumerableAsync(source);
}
Also includes IImmutableMapper<TSource, TDestination>
which is for mapping to immutable types like C# 9 record
's and can also be used for enum
types.
public record MapFrom(bool BooleanFrom, int IntegerFrom);
public record MapTo(bool BooleanTo, int IntegerTo);
public class DemoImmutableMapper : IImmutableMapper<MapFrom, MapTo>
{
public MapTo Map(MapFrom source) =>
new MapTo(source.BooleanFrom, source.IntegerFrom);
}
Provides ASP.NET Core middleware, MVC filters, extension methods and helper code for an ASP.NET Core project.
ILoggingBuilder Extensions
loggingBuilder
.AddIfElse(
hostingEnvironment.IsDevelopment(),
x => x.AddConsole(...).AddDebug(),
x => x.AddSerilog(...));
IConfiguration Extensions
this.configuration = new ConfigurationBuilder()
.SetBasePath(hostingEnvironment.ContentRootPath)
.AddJsonFile("config.json")
.AddJsonFile($"config.{hostingEnvironment.EnvironmentName}.json", optional: true)
.AddIf(
hostingEnvironment.IsDevelopment(),
x => x.AddUserSecrets())
.AddEnvironmentVariables()
.AddApplicationInsightsSettings(developerMode: !hostingEnvironment.IsProduction())
.Build();
IApplicationBuilder Extensions
application
.UseIfElse(
environment.IsDevelopment(),
x => x.UseDeveloperExceptionPage(),
x => x.UseStatusCodePagesWithReExecute("/error/{0}/"))
.UseIf(
environment.IsStaging(),
x => x.UseStagingSpecificMiddleware())
.UseStaticFiles()
.UseMvc();
[HttpGet("product/{id}/{title}", Name = "GetProduct")]
public IActionResult GetProduct(int id, string title)
{
var product = this.productRepository.Find(id);
if (product == null)
{
return this.NotFound();
}
// Get the actual friendly version of the title.
string friendlyTitle = FriendlyUrlHelper.GetFriendlyTitle(product.Title);
// Compare the title with the friendly title.
if (!string.Equals(friendlyTitle, title, StringComparison.Ordinal))
{
// If the title is null, empty or does not match the friendly title, return a 301 Permanent
// Redirect to the correct friendly URL.
return this.RedirectToRoutePermanent("GetProduct", new { id = id, title = friendlyTitle });
}
// The URL the client has browsed to is correct, show them the view containing the product.
return this.View(product);
}
Provides ASP.NET Core middleware, MVC filters, extension methods and helper code for an ASP.NET Core project implementing Swagger (OpenAPI).
ASP.NET Core tag helpers for Subresource Integrity (SRI), Referrer meta tags, OpenGraph (Facebook) and Twitter social network meta tags. Read more at:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"
asp-subresource-integrity-src="~/js/jquery.min.js"></script>
Twitter Cards
<twitter-card-summary-large-image username="@@RehanSaeedUK">
Open Graph (Facebook)
<open-graph-website site-name="My Website"
title="Page Title"
main-image="@(new OpenGraphImage(
Url.AbsoluteContent("~/img/1200x630.png"),
ContentType.Png,
1200,
630))"
determiner="OpenGraphDeterminer.Blank">
A unit test framework for project templates built using dotnet new.
dotnet restore
, dotnet build
and dotnet publish
commands.dotnet run
which gives you a HttpClient
that you can use to call the app and run further tests.public class ApiTemplateTest
{
public ApiTemplateTest() => DotnetNew.Install<ApiTemplateTest>("ApiTemplate.sln").Wait();
[Theory]
[InlineData("StatusEndpointOn", "status-endpoint=true")]
[InlineData("StatusEndpointOff", "status-endpoint=false")]
public async Task RestoreAndBuild_CustomArguments_IsSuccessful(string name, params string[] arguments)
{
using (var tempDirectory = TempDirectory.NewTempDirectory())
{
var dictionary = arguments
.Select(x => x.Split('=', StringSplitOptions.RemoveEmptyEntries))
.ToDictionary(x => x.First(), x => x.Last());
var project = await tempDirectory.DotnetNew("api", name, dictionary);
await project.DotnetRestore();
await project.DotnetBuild();
}
}
[Fact]
public async Task Run_DefaultArguments_IsSuccessful()
{
using (var tempDirectory = TempDirectory.NewTempDirectory())
{
var project = await tempDirectory.DotnetNew("api", "DefaultArguments");
await project.DotnetRestore();
await project.DotnetBuild();
await project.DotnetRun(
@"Source\DefaultArguments",
async (httpClient, httpsClient) =>
{
var httpResponse = await httpsClient.GetAsync("status");
Assert.Equal(HttpStatusCode.OK, httpResponse.StatusCode);
});
}
}
}
Name | Operating System | Status | History |
---|---|---|---|
Azure Pipelines | Ubuntu | ||
Azure Pipelines | Mac | ||
Azure Pipelines | Windows | ||
Azure Pipelines | Overall | ||
GitHub Actions | Ubuntu, Mac & Windows | ||
AppVeyor | Ubuntu, Mac & Windows |
Please view the contributing guide for more information.
Boxed.DotnetNewTest
NuGet package.刚入程序员这行的同学们,famework是什么?下面一起学习一下这个名词。简单阅读了解大概就好了,网上文字讲解太多,摘取部分收录。 框架(framework)是一个基本概念上的结构,用于去解决或者处理复杂的问题。这个广泛的定义使用的十分流行,尤其在软件概念。框架也能用于机械结构。 软件工程 什么是框架? 框架(Framework)是整个或部分系统的可重用设计,表现为一组抽象构件及构件实例间交互
完整报错如下:太长,把我认为重要信息用下划线标重点。 WARN 7612 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframew
报错 org.springframework.context.ApplicationContextException: Failed to start bean 'org.springframework.amqp.rabbit.config.internalRabbitListenerEndpointRegistry'; nested exception is org.springframewor
org.springframework.context.support.AbstractApplicationContext refresh错误 大家在学Spring的时候, Aop在Spring中的作用这一节点中,把所有文件都弄好以后,测试的时候会发现如下的错误 三月 03, 2021 6:27:04 下午 org.springframework.context.support.Abstract