Skip to content

Instantly share code, notes, and snippets.

View kelumKP's full-sized avatar
🏠
Working from home

Kelum kelumKP

🏠
Working from home
View GitHub Profile
@kelumKP
kelumKP / Program.cs
Created February 28, 2021 08:37
Sample Console Log App Program
using Autofac;
using log4net;
using System.Diagnostics.CodeAnalysis;
namespace SampleConsoleLogApp
{
[ExcludeFromCodeCoverage]
public class Program
{
public static void Main(string[] args)
{
@kelumKP
kelumKP / SampleInitialize.cs
Created February 28, 2021 08:35
Sample Console Log App
using log4net;
namespace SampleConsoleLogApp
{
public class SampleInitialize
{
private readonly ILog _log;
public SampleInitialize(ILog log)
{
_log = log;
@kelumKP
kelumKP / Program.cs
Created February 28, 2021 08:32
Program class Main method
[ExcludeFromCodeCoverage]
public static class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Console App Started!….");
ConfigureContainer().Resolve<SampleInitialize>().Run();
Console.WriteLine("Console App Stopped!….");
}
private static IContainer ConfigureContainer()
@kelumKP
kelumKP / SampleInitialize.cs
Last active February 28, 2021 08:31
Sample Initialize
public class SampleInitialize
{
private readonly ISampleService _oSampleService;
public SampleInitialize(ISampleService oSampleService)
{
_oSampleService = oSampleService;
}
public void Run()
{
var _list = _oSampleService.GetSampleList();
@kelumKP
kelumKP / EFModule.cs
Created February 28, 2021 08:29
EFModule class which is extending Module class
public class EFModule : Module
{
protected override void Load(ContainerBuilder builder)
{
try
{
builder.RegisterType(typeof(TestDBContext)).As(typeof(IContext)).InstancePerLifetimeScope();
}
catch (Exception ex)
{
@kelumKP
kelumKP / ServiceModule.cs
Created February 28, 2021 08:26
ServiceModule class file in Console Application
public class ServiceModule : Module
{
protected override void Load(ContainerBuilder builder)
{
try
{
builder.RegisterAssemblyTypes(System.Reflection.Assembly.Load("Service")).Where(t => t.Name.EndsWith("Service")).AsImplementedInterfaces().InstancePerLifetimeScope();
}
catch (Exception ex)
{
@kelumKP
kelumKP / TestDBContext.cs
Created February 28, 2021 08:24
Test DB Context
public class TestDBContext : DbContext, IContext
{
public TestDBContext() : base("Name=DB_CONNECTION_STRING"){}
public TestDBContext(DbConnection existingConnection, bool contextOwnsConnection) : base(existingConnection, contextOwnsConnection){}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
base.OnModelCreating(modelBuilder);
}
public IDbSet<SampleTable> SampleTables { get; set; }
@kelumKP
kelumKP / IContext.cs
Created February 28, 2021 08:22
DBContext IContext file
public interface IContext
{
IDbSet<SampleTable> SampleTables { get; set; }
DbSet<TEntity> Set<TEntity>() where TEntity : class;
DbEntityEntry<TEntity> Entry<TEntity>(TEntity entity) where TEntity : class;
Database Database { get; }
}
@kelumKP
kelumKP / SampleService.cs
Created February 28, 2021 08:21
Sample Service Implementation
public class SampleService : ISampleService
{
IContext _context;
public SampleService(IContext context)
{
_context = context;
}
public List<SampleTable> GetSampleList()
{
var availabelData = _context.SampleTables.ToList();
@kelumKP
kelumKP / ISampleService.cs
Created February 28, 2021 08:20
Sample Service Interface
public interface ISampleService
{
List<SampleTable> GetSampleList();
}