Skip to content

Commit

Permalink
Added examples and optional params
Browse files Browse the repository at this point in the history
  • Loading branch information
gregyjames committed Jan 17, 2024
1 parent 586b4f0 commit 8f517d4
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 6 deletions.
27 changes: 21 additions & 6 deletions OctaneEngine/EngineBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,37 @@ namespace OctaneEngineCore;

public static class EngineBuilder
{
public static IEngine Build(ILoggerFactory factory, IConfiguration config)
public static IEngine Build(ILoggerFactory factory = null, IConfiguration config = null)
{
var containerBuilder = new ContainerBuilder();
containerBuilder.RegisterInstance(factory).As<ILoggerFactory>();
containerBuilder.RegisterInstance(config).As<IConfiguration>();
if (factory != null)
{
containerBuilder.RegisterInstance(factory).As<ILoggerFactory>();
}

if (config != null)
{
containerBuilder.RegisterInstance(config).As<IConfiguration>();
}

containerBuilder.AddOctane();
var engineContainer = containerBuilder.Build();
var engine = engineContainer.Resolve<IEngine>();
return engine;
}

public static IEngine Build(ILoggerFactory factory, OctaneConfiguration config)
public static IEngine Build(ILoggerFactory factory = null, OctaneConfiguration config = null)
{
var containerBuilder = new ContainerBuilder();
containerBuilder.RegisterInstance(factory).As<ILoggerFactory>();
containerBuilder.RegisterInstance(config).As<OctaneConfiguration>();
if (factory != null)
{
containerBuilder.RegisterInstance(factory).As<ILoggerFactory>();
}

if (config != null)
{
containerBuilder.RegisterInstance(config).As<IConfiguration>();
}
containerBuilder.AddOctane();
var engineContainer = containerBuilder.Build();
var engine = engineContainer.Resolve<IEngine>();
Expand Down
42 changes: 42 additions & 0 deletions OctaneTester/Examples/Autofac.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.IO;
using System.Threading;
using Autofac;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using OctaneEngineCore;
using Serilog;
using Serilog.Sinks.SystemConsole.Themes;

namespace OctaneTester.Examples;

public class Autofac
{
public void AutofacExample()
{
var seriLog = new LoggerConfiguration()
.Enrich.FromLogContext()
.MinimumLevel.Error()
.WriteTo.Async(a => a.File("./OctaneLog.txt"))
.WriteTo.Async(a => a.Console(theme: AnsiConsoleTheme.Sixteen))
.CreateLogger();
var factory = LoggerFactory.Create(logging =>
{
logging.AddSerilog(seriLog);
});

var builder = new ConfigurationBuilder();
builder.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", true, true);
var configRoot = builder.Build();

var pauseTokenSource = new PauseTokenSource();

Check warning

Code scanning / CodeQL

Useless assignment to local variable Warning

This assignment to
pauseTokenSource
is useless, since its value is never read.
var cancelTokenSource = new CancellationTokenSource();

Check warning

Code scanning / CodeQL

Useless assignment to local variable Warning

This assignment to
cancelTokenSource
is useless, since its value is never read.

Check warning

Code scanning / CodeQL

Missing Dispose call on local IDisposable Warning

Disposable 'CancellationTokenSource' is created but not disposed.

var containerBuilder = new ContainerBuilder();
containerBuilder.RegisterInstance(factory).As<ILoggerFactory>();
containerBuilder.RegisterInstance(configRoot).As<IConfiguration>();
containerBuilder.AddOctane();
var engineContainer = containerBuilder.Build();
var engine = engineContainer.Resolve<IEngine>();

Check warning

Code scanning / CodeQL

Useless assignment to local variable Warning

This assignment to
engine
is useless, since its value is never read.
}
}
36 changes: 36 additions & 0 deletions OctaneTester/Examples/NoAutofac.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.IO;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using OctaneEngineCore;
using Serilog;
using Serilog.Sinks.SystemConsole.Themes;

namespace OctaneTester.Examples;

public class NoAutofac
{
public void NoAutoFacExample()
{
#region Logging Example
var seriLog = new LoggerConfiguration()
.Enrich.FromLogContext()
.MinimumLevel.Error()
.WriteTo.Async(a => a.File("./OctaneLog.txt"))
.WriteTo.Async(a => a.Console(theme: AnsiConsoleTheme.Sixteen))
.CreateLogger();
var factory = LoggerFactory.Create(logging =>
{
logging.AddSerilog(seriLog);
});
#endregion

#region Configuration Loading
var builder = new ConfigurationBuilder();
builder.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", true, true);
var configRoot = builder.Build();
#endregion

EngineBuilder.Build(factory, configRoot);
}
}
32 changes: 32 additions & 0 deletions OctaneTester/Examples/NoLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.IO;
using System.Threading;
using Autofac;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using OctaneEngineCore;
using Serilog;
using Serilog.Sinks.SystemConsole.Themes;

namespace OctaneTester.Examples;

public class NoLogger
{
public void NoLoggerExample()
{
#region Configuration Loading
var builder = new ConfigurationBuilder();
builder.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", true, true);
var configRoot = builder.Build();
#endregion

var pauseTokenSource = new PauseTokenSource();

Check warning

Code scanning / CodeQL

Useless assignment to local variable Warning

This assignment to
pauseTokenSource
is useless, since its value is never read.
var cancelTokenSource = new CancellationTokenSource();

Check warning

Code scanning / CodeQL

Useless assignment to local variable Warning

This assignment to
cancelTokenSource
is useless, since its value is never read.

Check warning

Code scanning / CodeQL

Missing Dispose call on local IDisposable Warning

Disposable 'CancellationTokenSource' is created but not disposed.

var containerBuilder = new ContainerBuilder();
containerBuilder.RegisterInstance(configRoot).As<IConfiguration>();
containerBuilder.AddOctane();
var engineContainer = containerBuilder.Build();
var engine = engineContainer.Resolve<IEngine>();

Check warning

Code scanning / CodeQL

Useless assignment to local variable Warning

This assignment to
engine
is useless, since its value is never read.
}
}

0 comments on commit 8f517d4

Please sign in to comment.