// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { Services = services; var connection = "Filename=db.sqlite";//Configuration.GetConnectionString("SQLite"); Services.AddEntityFrameworkSqlite() .AddDbContext <RepositoryContext>( options => options.UseSqlite(connection) ); Services.AddMvc(); Services.AddMemoryCache(); //Scoped services are injected into constructors that match the interface foreach (var t in ModelService.AllModels()) { Type unbound_interface = typeof(IRepository <>); //Interface for type construction Type unbound_instance = typeof(Repository <>); //Constructed service class for dependency injection Services.AddScoped( unbound_interface.MakeGenericType(t), //Bind reflected model type to interface unbound_instance.MakeGenericType(t) //Bind reflected model type to service ); } //Singleton services are created on first injection and re-used var scheduler = Chroniton.Singularity.Instance; //Background task scheduler Services.AddSingleton <Chroniton.ISingularity>(scheduler); scheduler.Start(); }
public T Update(T existing, T item = null) { if (item != null) { var vals = ModelService.GetModelValues(item); foreach (var prop in ModelService.GetPropertyInfo(typeof(T)) //Update the saved model .Where(p => p.SetMethod != null && p.SetMethod.IsPublic)) //If there is a public setter { var newprop = vals.Where(x => x.Key == prop.Name).FirstOrDefault().Value; prop.SetValue(existing, newprop); } } _context.Update(existing); _context.SaveChanges(); return(existing); }
public RepositoryContext(DbContextOptions <RepositoryContext> options) : base(options) { ModelTypes = ModelService.AllModels(); }