اشتراک‌ها
بهترین تمرینها برای ASP.NET Core Web API

In this post, we are going to write about what we consider to be the best practices while developing the .NET Core Web API project. How we can make it better and how to make it more maintainable.

We are going to go through the following sections:

بهترین تمرینها برای ASP.NET Core Web API
مطالب
مدیریت رخدادهای MouseLeftButtonDown و MouseLeftButtonUp در Silverlight

نیاز بود تا بتوان رخدادهای MouseLeftButtonDown و MouseLeftButtonUp یک TextBox را در Silverlight مدیریت کرد. شاید عنوان کنید که خیلی ساده است! دو روال رخداد گردان مربوطه را اضافه کنید و سپس تعاریف آن‌ها را در کدهای XAML خود قید نمائید. اما واقعیت این است که کار نمی‌کند! نه؛ کار نمی‌کند! :)

مشکل از کجاست؟ پاسخی که در MSDN در این مورد آمده است به صورت زیر می‌باشد:

"Certain control classes (for example Button) provide control-specific handling for mouse events such as MouseLeftButtonDown. The control-specific handling typically involves handling the event at a class level rather than at the instance level, and marking the MouseLeftButtonDown event data's Handled value as true such that the event cannot be handled by instances of the control class, nor by other objects anywhere further along the event route. In the case of Button, the class design does this so that the Click event can be raised instead."


به عبارتی رخداد Click زحمت کشیده و رخدادهای MouseLeftButtonDown و MouseLeftButtonUp را نیز handled معرفی می‌کند و دیگر روال رخدادگردان شما فراخوانی نخواهد شد (در WPF هم به همین صورت است) و موارد ذکر شده در visual tree یک TextBox منتشر نمی‌گردند.

راه حل چیست؟

حداقل دو راه حل وجود دارد:
الف) یک کنترل TextBox سفارشی را از کنترل TextBox اصلی باید به ارث برد و رخدادهایی را که توسط رخداد Click به صورت handled معرفی شده‌اند، unhandled کرد:

public class MyTextBox : TextBox
{
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonDown(e);
e.Handled = false;
}

protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonUp(e);
e.Handled = false;
}
}

ب) یا امکان گوش فرا دادن به رخدادهای handled نیز میسر است. فقط کافی است این گوش فرادهنده را توسط متد AddHandler که پارامتر آخر آن به true تنظیم شده است (رخدادهای handled نیز لحاظ شوند)، معرفی کرد:

public MainPage()
{
InitializeComponent();
txt1.AddHandler(FrameworkElement.MouseLeftButtonDownEvent,
new MouseButtonEventHandler(txt1_MouseLeftButtonDown), true);
}
private void txt1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{

//do something
}

نظرات مطالب
سفارشی سازی ASP.NET Core Identity - قسمت اول - موجودیت‌های پایه و DbContext برنامه
با سلام. من در یکی از سرویس‌ها می‌خواستم از transaction  استفاده کنم. این سرویس به این صورت است که ابتدا باید یک رکورد در یک جدول ذخیره کند و ایدی آن را در یک جدول دیگر ذخیره شود و این جداول هیچ ریلیشنی ندارد به همین خاطر میخواهم از ترنزاکشن استفاده کنم. یعنی از BeginTransaction و در اخر CommitTransaction و در صورتی که با خطا مواجه شوم از RollbackTransaction استفاده می‌کنم ولی متاسفانه خطای  زیر را می‌دهد. لطفا اگه میشه با یک مثالی بفرمایید که چطور باید از توابع بالا استفاده کنیم. ممنون
The configured execution strategy 'SqlServerRetryingExecutionStrategy' 
does not support user-initiated transactions. Use the execution strategy 
returned by 'DbContext.Database.CreateExecutionStrategy()'
to execute all the operations in the transaction as a retriable unit.
نظرات مطالب
شروع به کار با EF Core 1.0 - قسمت 14 - لایه بندی و تزریق وابستگی‌ها
باسلام؛ مشکلی که من بعد از پیاده سازی این موضوع دارم اینه که قبلا با تزریق مستقیم می‌تونستم به روش زیر یک Transaction ایجاد کنم و به راحتی چند تا SaveChanges رو فراخوانی کنیم ولی بعد از پیاده سازی این روش پیغام زیر رو بهم میده
IunitofWork The configured execution strategy 'SqlServerRetryingExecution Strategy' does not support user initiated transactions. Use the execution strategy returned by 'DbContext.Database.Create Execution Strategy()' to execute all the operations in the transaction as a retriable unit. 
اشتراک‌ها
Angular 6 منتشر شد

The 6.0.0 release of Angular is here! This is a major release focused less on the underlying framework, and more on the toolchain and on making it easier to move quickly with Angular in the future. 

Angular 6 منتشر شد
پیشنهادها
نحوه‌ی صحیح کار کردن با بوت استرپ
استفاده از فریم ورک‌های CSS هرچند امکان استفاده مجدد از کدها را به همراه یک سری از نکات پیشرفته‌ی طراحی، به صورت خودکار فراهم می‌کنند، اما ... در دراز مدت مانند یک ویروس در سراسر کدهای صفحات برنامه پخش می‌شوند. نیاز است این مساله را کنترل کرد.

منابع پیشنهادی