Initial
This commit is contained in:
4
files/AssemblyInfo.cs
Normal file
4
files/AssemblyInfo.cs
Normal file
@@ -0,0 +1,4 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly:InternalsVisibleTo("Domain.Tests")]
|
||||
[assembly:InternalsVisibleTo("Wiring")]
|
||||
24
files/DomainPorts.cs
Normal file
24
files/DomainPorts.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
|
||||
namespace Domain
|
||||
{
|
||||
public static class DomainPorts
|
||||
{
|
||||
private static IAdapterResolver _resolver;
|
||||
|
||||
internal static T Resolve<T>()
|
||||
{
|
||||
if (_resolver == null) throw new NullReferenceException("Adapter resolver is not set!");
|
||||
return _resolver.Resolve<T>();
|
||||
}
|
||||
|
||||
public static void SetResolver(IAdapterResolver resolver)
|
||||
{
|
||||
_resolver = resolver;
|
||||
}
|
||||
|
||||
// public static ILogService LogService => Resolve<ILogService>();
|
||||
// public static IConfigService ConfigService => Resolve<IConfigService>();
|
||||
// public static ICacheService CacheService => Resolve<ICacheService>();
|
||||
}
|
||||
}
|
||||
7
files/IAdapterResolver.cs
Normal file
7
files/IAdapterResolver.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Domain
|
||||
{
|
||||
public interface IAdapterResolver
|
||||
{
|
||||
T Resolve<T>();
|
||||
}
|
||||
}
|
||||
59
files/Wiring.cs
Normal file
59
files/Wiring.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using Autofac;
|
||||
using Domain;
|
||||
|
||||
namespace Wiring
|
||||
{
|
||||
public class Wiring : IAdapterResolver, IDisposable
|
||||
{
|
||||
private readonly IContainer _container;
|
||||
|
||||
public Wiring()
|
||||
{
|
||||
_container = Wire();
|
||||
DomainPorts.SetResolver(this);
|
||||
}
|
||||
|
||||
static IContainer Wire()
|
||||
{
|
||||
var builder = new ContainerBuilder();
|
||||
|
||||
//builder.RegisterAssemblyTypes(typeof(ConsoleOutput).Assembly)
|
||||
// .Where(t => typeof(IStartable).IsAssignableFrom(t))
|
||||
// .As<IStartable>()
|
||||
// .SingleInstance();
|
||||
//builder.Register(c => new ConsoleOutput()).As<IOutput>().SingleInstance();
|
||||
|
||||
RegisterSecondaryPorts(builder);
|
||||
RegisterPrimaryPorts(builder);
|
||||
return builder.Build();
|
||||
}
|
||||
|
||||
private static void RegisterSecondaryPorts(ContainerBuilder builder)
|
||||
{
|
||||
// builder.RegisterType<LogRepository>().As<ILogRepository>().SingleInstance();
|
||||
// builder.RegisterType<ConfigRepository>().As<IConfigRepository>().SingleInstance();
|
||||
// builder.RegisterType<CacheRepository>().As<ICacheRepository>().SingleInstance();
|
||||
// builder.RegisterType<UnitOfWorkFactory>().As<IUnitOfWorkFactory>().SingleInstance();
|
||||
}
|
||||
|
||||
private static void RegisterPrimaryPorts(ContainerBuilder builder)
|
||||
{
|
||||
// builder.RegisterType<LogService>().As<ILogService>().SingleInstance();
|
||||
// builder.RegisterType<ConfigService>().As<IConfigService>().SingleInstance();
|
||||
// builder.RegisterType<CacheService>().As<ICacheService>().SingleInstance();
|
||||
}
|
||||
|
||||
public T Resolve<T>()
|
||||
{
|
||||
return _container.Resolve<T>();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_container != null) {
|
||||
_container.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1
kickstart.cmd
Normal file
1
kickstart.cmd
Normal file
@@ -0,0 +1 @@
|
||||
powershell -executionpolicy bypass -File %~dp0\kickstart.ps1
|
||||
33
kickstart.ps1
Normal file
33
kickstart.ps1
Normal file
@@ -0,0 +1,33 @@
|
||||
New-Item -ItemType Directory -Force -Path output
|
||||
pushd output
|
||||
git init
|
||||
# solution
|
||||
dotnet new sln -n Solution
|
||||
dotnet new gitignore
|
||||
dotnet new globaljson
|
||||
dotnet new nugetconfig
|
||||
# domain project
|
||||
dotnet new classlib -n Domain
|
||||
dotnet sln add Domain
|
||||
# unit test project
|
||||
dotnet new nunit -n Domain.Tests
|
||||
dotnet add Domain.Tests package NSubstitute
|
||||
dotnet sln add Domain.Tests
|
||||
dotnet add Domain.Tests reference Domain
|
||||
# wiring project
|
||||
dotnet new classlib -n Wiring
|
||||
dotnet sln add Wiring
|
||||
dotnet add Wiring reference Domain
|
||||
dotnet add Wiring package Autofac
|
||||
# use webapi and/or console
|
||||
# webapi project
|
||||
#dotnet new webapi -n WebApi
|
||||
#dotnet sln add WebApi
|
||||
#dotnet add WebApi reference Domain
|
||||
#dotnet add WebApi reference Wiring
|
||||
# console project
|
||||
dotnet new console -n ConsoleApp
|
||||
dotnet sln add ConsoleApp
|
||||
dotnet add ConsoleApp reference Domain
|
||||
dotnet add ConsoleApp reference Wiring
|
||||
popd
|
||||
Reference in New Issue
Block a user