public static void Initialize(DutiesContext context) { using (context) { //context.Database.EnsureCreated(); // este método no ejecuta por defecto las migraciones, solo crea la base de datos context.Database.Migrate(); // Look for any user if (context.Resources.Any()) { return; // DB has been seeded } //Resources var resources = new Resource[] { new Resource ("ajones"), new Resource ("amuhid") }; foreach (Resource r in resources) { context.Resources.Add(r); } //context.SaveChangesAsync(); context.SaveChanges(); } }
public static async Task DispatchDomainEventsAsync(this IMediator mediator, DutiesContext ctx) { var domainEntities = ctx.ChangeTracker .Entries <Entity>() .Where(x => x.Entity.DomainEvents != null && x.Entity.DomainEvents.Any()); var domainEvents = domainEntities .SelectMany(x => x.Entity.DomainEvents) .ToList(); domainEntities.ToList() .ForEach(entity => entity.Entity.ClearDomainEvents()); foreach (var domainEvent in domainEvents) { await mediator.Publish(domainEvent); } }
public ResourceRepository(DutiesContext context) { // Evalua si es null en context que llega por parámetro _context = context ?? throw new ArgumentNullException(nameof(context)); }