Skip to content

Commit

Permalink
update into .net 8
Browse files Browse the repository at this point in the history
  • Loading branch information
BirajMainali committed Jan 23, 2024
1 parent 432b5cc commit a943f69
Show file tree
Hide file tree
Showing 32 changed files with 486 additions and 258 deletions.
33 changes: 15 additions & 18 deletions App.Base/App.Base.csproj
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<Folder Include="GenericRepository\Interface\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Dapper" Version="2.0.78" />
<PackageReference Include="Humanizer" Version="2.14.1" />
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="7.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="7.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="7.0.7" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="7.0.7" />
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="7.0.7" />
<PackageReference Include="Npgsql" Version="7.0.4" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.4" />
<PackageReference Include="Dapper" Version="2.1.28"/>
<PackageReference Include="Humanizer" Version="2.14.1"/>
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="8.0.1"/>
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="8.0.1"/>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.1"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="8.0.1"/>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0"/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0"/>
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="8.0.1"/>
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="8.0.1"/>
<PackageReference Include="Npgsql" Version="8.0.1"/>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0"/>
</ItemGroup>

</Project>
14 changes: 10 additions & 4 deletions App.Base/DiConfig.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
using App.Base.DataContext;
using System;
using System.Linq;
using App.Base.DataContext;
using App.Base.DataContext.Interfaces;
using App.Base.Providers;
using App.Base.Providers.Interface;
using App.Base.Repository;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;

namespace App.Base
{
public static class DiConfig
{
public static IServiceCollection UseBase(this IServiceCollection service)
=> service.AddScoped<IConnectionProvider, ConnectionProvider>()
public static IServiceCollection UseBase(this IServiceCollection services)
{
services.AddScoped<IConnectionProvider, ConnectionProvider>()
.AddScoped<IUow, Uow>();
services.AddScoped(typeof(IRepository<,>), typeof(Repository<,>));
return services;
}
}
}
16 changes: 16 additions & 0 deletions App.Base/Entities/FullAuditedEntity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#nullable enable
using System;
using App.Base.Constants;

namespace App.Base.Entities
{
public abstract class FullAuditedEntity<TKey>
{
public TKey Id { get; set; }
public DateTime CreatedDate { get; set; } = DateTime.Now;
public DateTime? UpdatedDate { get; set; }
public char RecStatus { get; set; } = Status.Active;
public TKey CreatedBy { get; set; }
public TKey UpdatedBy { get; set; }
}
}
17 changes: 0 additions & 17 deletions App.Base/GenericModel/GenericModel.cs

This file was deleted.

7 changes: 0 additions & 7 deletions App.Base/GenericModel/Interfaces/IGenericModel.cs

This file was deleted.

6 changes: 0 additions & 6 deletions App.Base/GenericModel/Interfaces/ISoftDelete.cs

This file was deleted.

71 changes: 0 additions & 71 deletions App.Base/GenericRepository/GenericRepository.cs

This file was deleted.

22 changes: 0 additions & 22 deletions App.Base/GenericRepository/Interface/IGenericRepository.cs

This file was deleted.

29 changes: 29 additions & 0 deletions App.Base/Repository/IRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;

namespace App.Base.Repository;

public interface IRepository<T, in TKey> where T : class
{
Task<T?> FindByAsync(TKey id);

T? Find(TKey id);

Task<int> GetCountAsync(Expression<Func<T, bool>> predicate);

Task<bool> CheckIfExistAsync(Expression<Func<T, bool>> predicate);

Task<T?> GetItemAsync(Expression<Func<T, bool>> predicate);

Task<List<T>> GetAllAsync(Expression<Func<T, bool>> predicate = null);

List<T> Get(Expression<Func<T, bool>> predicate);

IQueryable<T?> GetQueryable();

Task<T> FindOrThrowAsync(TKey id, string message);
}
53 changes: 53 additions & 0 deletions App.Base/Repository/Repository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;

namespace App.Base.Repository;

public class Repository<T, TKey> : IRepository<T, TKey> where T : class
{
private readonly DbSet<T> _dbSet;

public Repository(DbContext dbContext)
{
_dbSet = dbContext.Set<T>();
}

public virtual async Task<T?> FindByAsync(TKey id) => await _dbSet.FindAsync(id);

public virtual T? Find(TKey id) => _dbSet.Find(id);

public virtual async Task<int> GetCountAsync(Expression<Func<T, bool>> predicate)
{
predicate ??= x => true;
return await _dbSet.CountAsync(predicate);
}

public virtual async Task<bool> CheckIfExistAsync(Expression<Func<T, bool>> predicate) => await _dbSet.AnyAsync(predicate);

public virtual Task<T?> GetItemAsync(Expression<Func<T, bool>> predicate) => _dbSet.FirstOrDefaultAsync(predicate);

public virtual Task<List<T>> GetAllAsync(Expression<Func<T, bool>> predicate = null)
{
predicate ??= x => true;
return _dbSet.Where(predicate).ToListAsync();
}

public virtual List<T> Get(Expression<Func<T, bool>> predicate) => _dbSet.Where(predicate).ToList();

public virtual IQueryable<T?> GetQueryable() => _dbSet.AsQueryable();

public virtual async Task<T> FindOrThrowAsync(TKey id, string message)
{
var entity = await FindByAsync(id);
if (entity == null)
{
throw new Exception(message);
}

return entity;
}
}
4 changes: 2 additions & 2 deletions App.User/App.User.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="7.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="8.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 2 additions & 4 deletions App.User/DiConfig.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using App.User.Repositories;
using App.User.Repositories.Interfaces;
using App.User.Services;
using App.User.Services;
using App.User.Services.Interfaces;
using App.User.Validator;
using App.User.Validator.Interfaces;
Expand All @@ -11,6 +9,6 @@ namespace App.User;
public static class DiConfiguration
{
public static IServiceCollection UseUserConfiguration(this IServiceCollection services)
=> services.AddScoped<IUserRepository, UserRepository>().AddScoped<IUserService, UserService>()
=> services.AddScoped<IUserService, UserService>()
.AddScoped<IUserValidator, UserValidator>();
}
13 changes: 6 additions & 7 deletions App.User/Model/User.cs → App.User/Entity/AppUser.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
using App.Base.GenericModel.Interfaces;
using App.Base.Entities;

namespace App.User.Model;
namespace App.User.Entity;

public class User : IGenericModel
public class AppUser : FullAuditedEntity<long>
{
public long Id { get; set; }
public string Name { get; protected set; }
public string Gender { get; protected set; }
public string Email { get; protected set; }
public string Password { get; protected set; }
public string Address { get; protected set; }
public string Phone { get; protected set; }

public User()
public AppUser()
{
}

public User(string name, string gender, string email, string password, string address, string phone)
public AppUser(string name, string gender, string email, string password, string address, string phone)
=> Copy(name, gender, email, password, address, phone);

public void Update(string name, string gender, string email, string password, string address, string phone)
=> Copy(name, gender, email, password, address, phone);

private void Copy(string name, string gender, string email, string password, string address, string phone)
{
Name = name;
Expand All @@ -30,5 +30,4 @@ private void Copy(string name, string gender, string email, string password, str
Address = address;
Phone = phone;
}

}
5 changes: 3 additions & 2 deletions App.User/EntityRegistrar.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using Microsoft.EntityFrameworkCore;
using App.User.Entity;
using Microsoft.EntityFrameworkCore;

namespace App.User;

public static class EntityRegisterer
{
public static ModelBuilder AddUser(this ModelBuilder builder)
{
builder.Entity<Model.User>();
builder.Entity<AppUser>();
return builder;
}
}
Loading

0 comments on commit a943f69

Please sign in to comment.