مطالب
سفارشی سازی Resourceها بر اساس نوع مشتری در Asp.net Core
فرض کنید یک برنامه‌ی تحت وب را نوشته‌ایم که برای مدارس و همچنین برای هنرستان‌ها مورد استفاده قرار می‌گیرد. هنگامیکه برنامه را برای مشتری پابلیش می‌کنیم، از کلمات مدرسه و دانش آموز استفاده کرده‌ایم. اما مشتری هنرستان از ما می‌خواهد این عبارت‌ها، به هنرستان و هنرآموز تغییر کنند. خوب یک راه‌حل این هست که ریسورس‌ها را قبل از هر پابلیش تغییر دهیم و همیشه باید حواسمان به این موضوع باشد که الان برنامه را برای مشتری مدرسه پابلیش می‌کنیم، یا مشتری هنرستان. در این مطلب به کمک DI توکار  Asp.net Core، یک راهکار را برای این موضوع ارائه کرده‌ایم.

ابتدا دو کلاس را به نام‌های SchoolResource و ArtSchoolResource و فایلهای ریسورس مربوطه را به نام‌های  SchoorResource.fa.resx و ArtSchoolResource.fa.resx ایجاد می‌کنیم. این دو فایل در حقیقت Shared Resource  هستند:

همچنین یک Interface را نیز به نام IResourceManager تعریف می‌کنیم:

public interface IResourceManager
    {
         IStringLocalizer Localizer { get; }
    }

سپس دو کلاس دیگر را ایجاد کرده و آنها را از این اینترفیس مشتق می‌کنیم. در این اینترفیس، یک خصوصیت Localizer از نوع IStringLocalizer وجود دارد که باید در این کلاس‌ها پیاده سازی شود. این کار را به کمک  IStringLocalizerFactory انجام داده و مشخص می‌کنیم هر کلاس، از کدام ریسورس استفاده کند:

 public class SchoolResourceManager : IResourceManager
    {       
        public SchoolResourceManager (IStringLocalizerFactory factory)
        {
            Localizer = factory.Create(typeof(SchoolResource));
        }
        public IStringLocalizer Localizer { get; }
    }
 public class ArtSchoolResourceManager : IResourceManager
    {       
        public ArtSchoolResourceManager(IStringLocalizerFactory factory)
        {
            Localizer = factory.Create(typeof(ArtSchoolResource));
        }
        public IStringLocalizer Localizer { get; }
    }


سپس در فایل appsetting.json پروژه، یک کلید را تعریف می‌کنیم تا مشخص کند، نوع application، از نوع مدرسه هست یا از نوع هنرستان:

{
  "ConnectionStrings": {
    "str": "..."
  },
  "Type": "ArtSchool" 
}

در متد ConfigureServices در فایل  startup تعیین می‌کنیم هنگام شروع به کار برنامه، با توجه به مقدار درون appsetting، کدام سرویس (manager) تزریق شود:

 public void ConfigureServices(IServiceCollection services)
{
            services.AddLocalization();
            services.AddSingleton<SchoolResourceManager>();
            services.AddSingleton<ArtSchoolResourceManager>();
            services.AddSingleton<IResourceManager>(cnf =>
            {
                var type = Configuration.GetSection("Type").Value;
                if (type == "ArtSchool")
                    return cnf.GetServices<ArtSchoolResourceManager>().FirstOrDefault();
                    

                return cnf.GetServices<SchoolResourceManager>().FirstOrDefault();
            });
}

خوب حالا با خیال راحت برنامه را توسعه می‌دهیم و در view‌ها و Controller‌ها از همان کلیدهای School و Student استفاده می‌کنیم:

: View

@inject IResourceManager ResourceManager

<h2>@ResourceManager.Localizer["Student"] : </h2>

 :Controller

 public class TestController : Controller
    {        
        private readonly IResourceManager _resourceManager;
       
        public TestController (IResourceManager resourceManager)
        {
             _resourceManager = resourceManager;
        }
}
اشتراک‌ها
سوالات مصاحبه ای ASP.NET Core
What is .NET Core?
What is ASP.NET Core?
Can ASP.NET Core work with the .NET framework?
What is Kestrel?
Dependency Injection in ASP.NET Core?
The configuration in ASP.NET Core?
Talk about Logging in ASP.NET Core?
Explain Middleware in ASP.NET Core?
Explain startup process in ASP.NET Core?
سوالات مصاحبه ای ASP.NET Core
اشتراک‌ها
به اشتراک گذاری کدهای ui در اپلیکیشن های ios , android

One of the most exciting announcements during this year’s Connect(); event was the ability to embed .NET libraries into existing iOS (Objective-C/Swift) and Android (Java) applications with .NET Embedding. This is great because you can start to share code between your iOS and Android applications, and you can also share the user interface between your apps when you combine .NET Embedding with Xamarin.Forms Native Forms. This means that you can leverage your existing investments and apps without having to re-write them from scratch to start adding cross-platform logic and UI. In fact, during the Connect(); keynote I showed how I was able to extend the open source Swift-based Kickstarter iOS application with .NET Embedding and Xamarin.Forms Native Forms. You can check out the clip below. 

به اشتراک گذاری کدهای ui در اپلیکیشن های  ios , android
اشتراک‌ها
مدل پیکره بندی جدید در ASP.NET CORE

ASPNET Core has a lot of changes compared with the others versions of ASP.NET. One change I want to highlight is the new way to configure settings. With previous versions, this configuration was made by using the common file web.config, but this file simply doesn’t exist anymore in ASP.NET Core. Instead, a new easy way to declare and access to the settings is provided. Let’s take a look. 

مدل پیکره بندی جدید در ASP.NET CORE
اشتراک‌ها
Console Application ها در NET Core.

دات نت core فقط برای برنامه‌های تحت وب نیست!

Console Application ها در NET Core.
نظرات مطالب
کنترل عمومی فایل‌های آپلودی در ASP.NET MVC
معادل این مطلب در برنامه‌های ASP.NET Core

ابتدا بسته‌ی نیوگت DNTCommon.Web.Core را نصب کنید:
PM> Install-Package DNTCommon.Web.Core
سپس مثالی از UploadFileExtensions و AllowUploadSafeFiles آن‌را در اینجا می‌توانید مشاهده کنید.
نظرات مطالب
روش یافتن لیست تمام کنترلرها و اکشن‌ متدهای یک برنامه‌ی ASP.NET Core
خلاصه نکات این مطلب در برنامه‌های ASP.NET Core

ابتدا بسته‌ی نیوگت DNTCommon.Web.Core را نصب کنید:
PM> Install-Package DNTCommon.Web.Core
سپس مثالی از IMvcActionsDiscoveryService آن‌را در اینجا می‌توانید مشاهده کنید.   
نظرات مطالب
تهیه قالب برای ارسال ایمیل‌ها در ASP.NET Core توسط Razor Viewها
خلاصه نکات این مطلب در برنامه‌های ASP.NET Core

ابتدا بسته‌ی نیوگت DNTCommon.Web.Core را نصب کنید:
PM> Install-Package DNTCommon.Web.Core
سپس مثالی از IViewRendererService آن‌را در اینجا می‌توانید مشاهده کنید.