Skip to content

Instantly share code, notes, and snippets.

@danielplawgo
danielplawgo / AddCategory.cs
Created September 27, 2018 03:36
Migracja schematu bazy danych w Entity Framework
public partial class AddCategory : DbMigration
{
public override void Up()
{
CreateTable(
"dbo.Categories",
c => new
{
Id = c.Int(nullable: false, identity: true),
Name = c.String(),
@danielplawgo
danielplawgo / IVerb.cs
Created September 20, 2018 04:26
Obsługa parametrów w aplikacji konsolowej za pomocą CommandLineParser
public interface IVerb
{
void Run();
}
public class CategoriesController : Controller
{
private Lazy<ICategoryRepository> _categoryRepository;
protected ICategoryRepository CategoryRepository
{
get { return _categoryRepository.Value; }
}
private Lazy<IMapper> _mapper;
@danielplawgo
danielplawgo / CacheInterceptor.cs
Last active January 21, 2019 05:17
Jak automatycznie ponawiać operacja oraz cachować dane z interceptorami w Autofac?
public class CacheInterceptor : IInterceptor
{
private ICacheService _cacheService;
public CacheInterceptor(ICacheService cacheService)
{
_cacheService = cacheService;
}
public void Intercept(IInvocation invocation)
@danielplawgo
danielplawgo / Program.cs
Created September 2, 2018 04:16
Jak ponawiać operacje w .NET z wykorzystaniem Polly?
class Program
{
private static NLog.Logger _logger = NLog.LogManager.GetCurrentClassLogger();
static void Main(string[] args)
{
_logger.Info("Start");
try
{
var content = Download("http://plawgo.pl");
@danielplawgo
danielplawgo / CacheService.cs
Created August 27, 2018 13:01
Jak cachować dane w .NET? Kilka słów o CacheManager oraz Redis
public class CacheService : ICacheService
{
private ICacheManager<object> _cache;
private const string _defaultCacheName = "defaultCache";
public CacheService()
{
var builder = ConfigurationBuilder.LoadConfiguration(_defaultCacheName).Builder;
builder.WithMicrosoftLogging(s => s.AddNLog());
@danielplawgo
danielplawgo / DateService.cs
Last active August 21, 2018 04:58
Jak automatycznie zmieniać czas lokalny na UTC w ASP.NET MVC?
public class DateService : IDateService
{
public DateTime ConvertToUtc(DateTime dateTime)
{
TimeZoneInfo timeZone = TimeZoneInfo.FindSystemTimeZoneById(GetTimezone());
var date = DateTime.SpecifyKind(dateTime, DateTimeKind.Unspecified);
return TimeZoneInfo.ConvertTimeToUtc(date, timeZone);
}
public DateTime ConvertToLocal(DateTime dateTime)
@danielplawgo
danielplawgo / Products1Controller.cs
Created August 12, 2018 08:56
Jak zmienić generowanie kodu w ASP.NET MVC?
public class Products1Controller : Controller
{
private DataContext db = new DataContext();
// GET: /Products1/
public ActionResult Index()
{
return View(db.Products.ToList());
}
public class BaseModel
{
public BaseModel()
{
IsActive = true;
}
public int Id { get; set; }
public bool IsActive { get; set; }
@danielplawgo
danielplawgo / Benchmarks1.cs
Created July 26, 2018 04:14
Jeden czy wiele plików resource, a wydajność
public class Benchmarks
{
[Benchmark]
public void UsingResources()
{
var test = Resources.One;
}
}