Skip to content

Instantly share code, notes, and snippets.

View subhendu-de's full-sized avatar
👓
Coder by Choice

Subhendu De subhendu-de

👓
Coder by Choice
View GitHub Profile
//Create a CTS to launch a task in charge of renewing the message lock
var brokeredMessageRenewCancellationTokenSource = new CancellationTokenSource();
try {
var brokeredMessage = _client.Receive();
var brokeredMessageRenew = Task.Factory.StartNew(() => {
while (!brokeredMessageRenewCancellationTokenSource.Token.IsCancellationRequested) {
//Based on LockedUntilUtc property to determine if the lock expires soon
if (DateTime.UtcNow > brokeredMessage.LockedUntilUtc.AddSeconds( - 10))
{
// If so, repeat the message brokeredMessage.RenewLock();
dotnet run --project .\netcore21\src\eKart.Api\eKart.Api.csproj
dotnet run --project .\netcore21\src\eKart.Api\eKart.Api.csproj
using Swashbuckle.AspNetCore.Swagger;
namespace eKart.Api
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Register the Swagger generator, defining 1 or more Swagger documents
dotnet add package Swashbuckle.AspNetCore
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using eKart.Api.Model;
namespace eKart.Api.Controllers
{
[Route("api/[controller]")]
dotnet ef migrations add InitialCreate
dotnet ef database update
using eKart.Api.Model;
using Microsoft.EntityFrameworkCore;
public void ConfigureServices(IServiceCollection services)
{
services.AddScoped<IDatasourceContext, SQLServerContext>();
services.AddDbContext(options => options.UseSqlServer(@"Server=.;Database=eKart;Trusted_Connection=True;ConnectRetryCount=0"));
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}
using System;
using Microsoft.EntityFrameworkCore;
namespace eKart.Api.Model
{
public class SQLServerContext: DbContext, IDatasourceContext
{
public SQLServerContext(DbContextOptions options):base(options)
{}
public DbSet Products{get; set; }
using System;
using Microsoft.EntityFrameworkCore;
namespace eKart.Api.Model
{
public interface IDatasourceContext: IDisposable
{
DbSet Products{ get; set; }
int SaveChanges();
}
namespace eKart.Api.Model
{
public class Product
{
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.None)]
public int ID { get; set; }
public string Name {get; set; }
}
}