اشتراک‌ها
وب سایت خود با Grunt متحول کنید

This article is in the Product Showcase section for our sponsors at CodeProject. These reviews are intended to provide you with information on products and services that we consider useful and of value to developers. 

وب سایت خود با Grunt متحول کنید
اشتراک‌ها
انتشار Team Explorer Everywhere 14.0.2

We recently released a small update to Team Explorer Everywhere – a cross platform command line and Eclipse plug-in for working Team Foundation Server and Visual Studio Team Services. 

انتشار Team Explorer Everywhere  14.0.2
اشتراک‌ها
کتابخانه‌ی JSONAPI.NET

JSONAPI.NET is a set of utility classes that aim to make it possible to implement JSON API spec compliant RESTful web services quickly and easily using ASP.NET MVC WebAPI. 

کتابخانه‌ی JSONAPI.NET
نظرات مطالب
امن سازی برنامه‌های ASP.NET Core توسط IdentityServer 4x - قسمت پنجم - پیاده سازی ورود و خروج از سیستم
//...
.AddOpenIdConnect("oidc", options =>
                {
                    // ...
                    options.Events = new OpenIdConnectEvents
                    {
                        OnTokenValidated = async ctx =>
                        {
                          // how to access claims
                          var user = ctx.Principal;                    
                          var email = user.Claims.FirstOrDefault(claim => claim.Type == "email").Value;

                          // how to access services
                          var db = ctx.HttpContext.RequestServices.GetRequiredService<MyDb>();

                          // ....
                        }
                    };
                });
نظرات مطالب
توزیع پروژه‌های ASP.NET Core 1.1 بدون ارائه فایل‌های View آن
برای کامپایل مجدد فایل‌های ویو (cshtml) در هنگام اجرای برنامه (runtime compilationو مشاهده تغییرات اعمال شده بر روی آن‌ها به صورت زیر عمل می‌کنیم:

  • ASP.NET Core 2.2
services.AddMvc()
    .AddRazorOptions(options => options.AllowRecompilingViewsOnFileChange = true);

  • ASP.NET Core 3.0 , 3.1
ابتدا بسته  Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation به پروژه اضافه کرده و سپس از کد زیر استفاده می‌کنیم:
public void ConfigureServices(IServiceCollection services)
{
    services.AddControllersWithViews()
        .AddRazorRuntimeCompilation();
    //...
}
 
نظرات مطالب
ارتقاء به ASP.NET Core 1.0 - قسمت 6 - سرویس‌ها و تزریق وابستگی‌ها
public async Task<HttpClient> GetHttpClientAsync()
        {
            var currentContext = _httpContextAccessor.HttpContext;
            // ...
        }
public void ConfigureServices(IServiceCollection services)
{
            services.AddHttpContextAccessor();
در متد configure در startup سرویس خودم رو به این شکل فراخوانی کردم
var df = languageService.GetAll().GetAwaiter().GetResult();
اما مقدار currentContext در متد GetHttpClient نال هست. آیا اشتباهی در تزریق وابستگی‌ها رخ داده؟ 
نظرات مطالب
ارتقاء به ASP.NET Core 1.0 - قسمت 7 - کار با فایل‌های config
یک نکته‌ی تکمیلی: تعریف متد AddConfig و عدم نیاز به استفاده‌ی از IOptions برای کار با آن
کدهای متد الحاقی AddConfig زیر:
services.AddConfig<MySettings>(Configuration.GetSection("MySettings"));
به این صورت تعریف شده‌است:
public static class ServiceCollectionExtensions
{
    public static TSettings AddConfig<TSettings>(this IServiceCollection services, IConfiguration configuration)
        where TSettings : class, new()
    {
        return services.AddConfig<TSettings>(configuration, options => { });
    }

    public static TSettings AddConfig<TSettings>(this IServiceCollection services, IConfiguration configuration, Action<BinderOptions> configureOptions)
        where TSettings : class, new()
    {
        if (services == null) { throw new ArgumentNullException(nameof(services)); }
        if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); }
        TSettings setting = configuration.Get<TSettings>(configureOptions);
        services.TryAddSingleton(setting);
        return setting;
    }
}
در اینجا وهله‌ای از کلاس تنظیم خوانده شده را به صورت Singleton در سیستم ثبت می‌کند. بنابراین برای دریافت آن در برنامه، الزامی به استفاده‌ی از اینترفیس IOptions نبوده و می‌توان مستقیما خود کلاس تنظیم را به سازنده‌ی کلاس استفاده کننده‌ی از آن تزریق کرد:
private readonly MySettings _settings;

public MyViewComponent(MySettings settings)
{
    _settings = settings;
}
مزیت آن حذف وابستگی مرتبط با IOptions در قسمت‌های مختلف برنامه است.
نظرات مطالب
حذف فضاهای خالی در خروجی صفحات ASP.NET MVC
جهت فشرده سازی چون gzip در net core. میتوان از این middleware به شکل زیر استفاده کرد:
public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddResponseCompression();

        services.AddResponseCompression(options =>
        {
            options.Providers.Add<GzipCompressionProvider>();
            options.EnableForHttps = true;
        });
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        app.UseResponseCompression();
    }
}