This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Autofac; | |
using log4net; | |
using System.Diagnostics.CodeAnalysis; | |
namespace SampleConsoleLogApp | |
{ | |
[ExcludeFromCodeCoverage] | |
public class Program | |
{ | |
public static void Main(string[] args) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using log4net; | |
namespace SampleConsoleLogApp | |
{ | |
public class SampleInitialize | |
{ | |
private readonly ILog _log; | |
public SampleInitialize(ILog log) | |
{ | |
_log = log; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SampleInitialize | |
{ | |
private readonly ISampleService _oSampleService; | |
public SampleInitialize(ISampleService oSampleService) | |
{ | |
_oSampleService = oSampleService; | |
} | |
public void Run() | |
{ | |
var _list = _oSampleService.GetSampleList(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class EFModule : Module | |
{ | |
protected override void Load(ContainerBuilder builder) | |
{ | |
try | |
{ | |
builder.RegisterType(typeof(TestDBContext)).As(typeof(IContext)).InstancePerLifetimeScope(); | |
} | |
catch (Exception ex) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SampleService : ISampleService | |
{ | |
IContext _context; | |
public SampleService(IContext context) | |
{ | |
_context = context; | |
} | |
public List<SampleTable> GetSampleList() | |
{ | |
var availabelData = _context.SampleTables.ToList(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface ISampleService | |
{ | |
List<SampleTable> GetSampleList(); | |
} |
NewerOlder