I wonder about below new() keyword. new() is in the base declaration statement along with IDisposable where C : DbContext and IDisposedTracker.
But I wonder about new() expression. Is this an anonymous base class declaration?
But notice a couple of arrow that I marked next to new(). Those curly brackets are owned by public class RepositoryBase, not by new().
What is new() here?
namespace PersonRepository
{
public class RepositoryBase<C> : IDisposable where C : DbContext, IDisposedTracker, new()
->{
public RepositoryBase()
{
DataContext.Database.CreateIfNotExists();
}
private C _DataContext;
public virtual C DataContext
{
get
{
if (_DataContext == null || _DataContext.IsDisposed)
{
_DataContext = new C();
AllowSerialization = true;
//Disable ProxyCreationDisabled to prevent the "In order to serialize the parameter, add the type to the known types collection for the operation using ServiceKnownTypeAttribute" error
}
return _DataContext;
}
}
//partly omitted
public void Save()
{
DataContext.SaveChanges();
}
public void Dispose()
{
if (DataContext != null) DataContext.Dispose();
}
}<-
}