Implementing N-tier with Entity framework and repo pattern

I’m trying to clean up this code but can’t figure out the best way to go about it.

The UI will access the business layer and shouldn’t know about EFContext in doing this I end up with an almost exact copy of the EFContext class in my RepoBase class. If I need a entity specific method, I’m creating a entity specific repo and deriving from the RepoBase

MS examples seem to skip the RepoBase and just implement each CRUD method in each and every entity, this seems like even more code duplication.

RepoBase does provide separation but at the cost of duplication. I would like to know if there’s a better way.

Data Access Layer

public interface IDataContext {     T GetById<T>(int id);     void Delete<T>(T entity); }  public class EFContext : DbContext, IDataContext {     public virtual DbSet<Student> Student { get; set; }      public T GetById<T>(int id)     {         ...     }      public void Delete<T>(T entity)     {         ...     }  } 

Business Logic Layer

// Generic repo public class RepoBase {     private IDataContext _context;      public RepoBase(IDataContext context)     {         _context = context;     }      public T GetById<T>(int id)     {         return _context.GetById<T>(id);     } }  // Specific repo public class StudentRepo : RepoBase {     public Student GetByStudentId(int studentId)     {         ...     } } 

Custom SGD optimizer in Mathematica neural network framework?

I have a new approach to SGD optimizer, and thought to try to test it in Mathematica. It uses gradients to simultaneously maintain online parabola model for smarter choice of step size – I only need to ask for gradients and be able to manually update parameters.

Is it doable within Mathematica neural network framework? I see NetPortGradient, but how to modify parameters?

As it seems a common research direction, maybe there is some simple example?

Is such “transparent” testing framework a good idea? [on hold]

Here is an example in R, but the concept applies to any language that supports file IO. I’m presenting it in R just because its special operator overriding feature makes the syntax looks nicer.

`%<-verify%` <- function(x, new.value) {   name <- deparse(substitute(x))   save.file <- paste0(name, '.rds')    if (!file.exists(save.file)) {     message(paste('Generating', save.file))     saveRDS(new.value, save.file)     assign(name, new.value, inherits=TRUE)   } else {     old.value <- readRDS(save.file)     if (!isTRUE(delta <- all.equal(old.value, new.value))) {       warning(delta)     } else {       message('checked')     }     assign(name, old.value, inherits=TRUE)   } } 

Let me explain it in action. Say you just receive a legacy codebase and want to clean that mess up.

> get.answer <- function() bitwXor(0xDEAD, 0xBEEF) %% 100 

First, you need to run some examples, so that the test framework can learn what the result should be. When a name is assigned with %<-verify% for the first time, its value is stored to a file (named after it to prevent namespace collisions).

> source('test-util.R') > answer %<-verify% get.answer() Generating answer.rds > answer [1] 42 

All subsequent %<-verify% to this name automatically checks the new value against the saved value, and emit a warning if they don’t agree.

> get.answer <- function() 43 > answer %<-verify% get.answer() Warning message: In answer %<-verify% get.answer() : Mean relative difference: 0.02380952 

Effectively, this prevents the codebase from being broken by the new changes.

> get.answer <- function() 42 > answer %<-verify% get.answer() checked 

Note that you should only use %<-verify% on the interfaces you care about, for example, the exported functions. If you i %<-verify% i + 1 within a loop then be prepared for a wall of warnings.

Its main merit is transparency, that you can just replace <- with %<-% and the check is done automatically. People are lazy, so making tests easier to implement basically creates more tests, and errors can be detected at an earlier stage.

Do you think this is a good practice?

PHP Framework

Hi, I'm Juan, I'm 26 years old and I'm a programmer with 5 years of experience in the PHP area, I'm currently with Laravel
Any recommendations of which other Framework to use?