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 / 0_reuse_code.js
Created August 7, 2017 15:04
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@kelumKP
kelumKP / web.config.xml
Last active February 28, 2021 07:16
ConnectionStrings
<add name="SQLAuthentication_ConnectionString" connectionString="Data Source=SQL_AUTH_DB_SERVER;Initial Catalog=SQL_AUTH_DB_NAME;Persist Security Info=True;User ID=SQL_AUTH_DB_USER_ID;pwd=SQL_AUTH_DB_USER_PASSWORD;MultipleActiveResultSets=true;" providerName="System.Data.SqlClient" />
<add name="WindowsAuthentication_ConnectionString" connectionString="Data Source=WINDOWS_SQL_AUTH_DB_SERVER;Initial Catalog=WINDOWS_SQL_AUTH_DB_NAME;Persist Security Info=True;User ID=WINDOWS_SQL_AUTH_DB_USER_ID;pwd=WINDOWS_SQL_AUTH_DB_USER_PASSWORD;MultipleActiveResultSets=true;" providerName="System.Data.SqlClient" />
@kelumKP
kelumKP / SampleTable.cs
Created February 28, 2021 08:18
Sample Table Class File
public class SampleTable
{
public int ID { get; set; }
public string Name { get; set; }
}
@kelumKP
kelumKP / ISampleService.cs
Created February 28, 2021 08:20
Sample Service Interface
public interface ISampleService
{
List<SampleTable> GetSampleList();
}
@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 / 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 / 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 / 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 / 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 / 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();