View compositekey.cs
class MyContext : DbContext
{
public DbSet<Car> Cars { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Car>()
.HasKey(c => new { c.State, c.LicensePlate });
}
}
View fromsql.cs
var blogs = context.Blogs
.FromSql("SELECT * FROM Blogs")
.ToList();
View efcoredbcontext.cs
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseMySql(_connection);
}
View controlleroption.cs
[Route("api/[controller]")]
public class CustomersController : Controller
{
private readonly CustomerRepository _customerRepository;
public CustomersController()
{
_customerRepository = new CustomerRepository();
}
View controller404.cs
[Route("api/[controller]")]
public class CustomersController : Controller
{
private readonly CustomerRepository _customerRepository;
public CustomersController()
{
_customerRepository = new CustomerRepository();
}
View controller.cs
[Route("api/[controller]")]
public class CustomersController : Controller
{
private readonly CustomerRepository _customerRepository;
public CustomersController()
{
_customerRepository = new CustomerRepository();
}
View GreetingCommandHandler.cs
internal class GreetingCommandHandler : RequestHandler<GreetingCommand>
{
[UseCommandSourcing(step: 1, timing: HandlerTiming.Before)]
public override GreetingCommand Handle(GreetingCommand command)
{
Console.WriteLine("Hello {0}", command.Name);
return base.Handle(command);
}
}
View program.cs
internal class Program
{
private static void Main(string[] args)
{
var registry = new SubscriberRegistry();
registry.Register<GreetingCommand, GreetingCommandHandler>();
var tinyIoCContainer = new TinyIoCContainer();
tinyIoCContainer.Register<IHandleRequests<GreetingCommand>, GreetingCommandHandler>();
View addToCartHandler.cs
public class AddToCartHandler : IAsyncRequestHandler<AddToCart>
{
private readonly MusicStoreContext _dbContext;
private readonly ILogger<AddToCart> _logger;
// Ctor..
public async Task Handle(AddToCart message)
{
var addedAlbum = await _dbContext.Albums
View logger.cs
public class AddToCartLogger : IRequestPostProcessor<AddToCart, Unit>
{
private readonly ILogger<AddToCart> _logger;
public AddToCartLogger(ILogger<AddToCart> logger)
{
_logger = logger;
}
public Task Process(AddToCart request, Unit response)
{