Skip to content

Commit

Permalink
only required config in ctor
Browse files Browse the repository at this point in the history
  • Loading branch information
maisiesadler committed May 6, 2021
1 parent 3971b11 commit 40811dd
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
11 changes: 9 additions & 2 deletions src/DepTree.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,15 @@ static int Main(string[] args)
// System.Console.WriteLine(JsonSerializer.Serialize(applicationConfig));

var assembly = Assembly.LoadFrom(applicationConfig.AssemblyLocation);
var config = new DependencyTreeConfig(assembly, applicationConfig.AssemblyConfiguration, skipAssemblies: applicationConfig.Skip);
config.InterfaceResolverType = applicationConfig.InterfaceResolverType;
var config = new DependencyTreeConfig(assembly, applicationConfig.AssemblyConfiguration)
{
InterfaceResolverType = applicationConfig.InterfaceResolverType,
SkipAssemblies = applicationConfig.Skip,

// todo:
// StartupName = applicationConfig.StartupName,
// OutputFormat = applicationConfig.OutputFormat,
};

var nodes = new List<DependencyTreeNode>();
var tree = new DependencyTree(config);
Expand Down
5 changes: 4 additions & 1 deletion src/DepTree.Tests/DependencyTreeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ public void CanResolveInterfaceDependenciesWithConfig()
var assembly = this.GetType().Assembly;
var cfgBuilder = new ConfigurationBuilder();
var iconfiguration = cfgBuilder.Build();
var config = new DependencyTreeConfig(assembly, iconfiguration, startupName: "StartupWithConfig");
var config = new DependencyTreeConfig(assembly, iconfiguration)
{
StartupName = "StartupWithConfig",
};
var fullTypeName = "DepTree.Tests.DependencyTreeTests+ExampleTypeWithInterfaceDeps";

var tree = new DependencyTree(config);
Expand Down
10 changes: 8 additions & 2 deletions src/DepTree.Tests/DiagramTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ public void CanCreateDiagramForSimpleDependency()
public void CanCreateDiagramForDependencyWithImplementation()
{
var assembly = this.GetType().Assembly;
var config = new DependencyTreeConfig(assembly, startupName: "DepTree.Tests.DiagramTests+Startup");
var config = new DependencyTreeConfig(assembly)
{
StartupName = "DepTree.Tests.DiagramTests+Startup",
};
var fullTypeName = "DepTree.Tests.DiagramTests+ExampleTypeWithInterfaceDeps";

var tree = new DependencyTree(config);
Expand All @@ -53,7 +56,10 @@ public void CanCreateDiagramForDependencyWithImplementation()
public void MultipleRegistrationsDedupedAndNoted()
{
var assembly = this.GetType().Assembly;
var config = new DependencyTreeConfig(assembly, startupName: "DepTree.Tests.DiagramTests+Startup");
var config = new DependencyTreeConfig(assembly)
{
StartupName = "DepTree.Tests.DiagramTests+Startup"
};
var fullTypeName = "DepTree.Tests.DiagramTests+ExampleTypeWithInterfaceDeps";

var tree = new DependencyTree(config);
Expand Down
10 changes: 5 additions & 5 deletions src/DepTree/DependencyTreeConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ namespace DepTree
public class DependencyTreeConfig
{
public Assembly Assembly { get; }
public string StartupName { get; }
public IConfiguration Configuration { get; set; }
public IConfiguration Configuration { get; }
public string StartupName { get; set; } = "Startup";
public HashSet<string> SkipAssemblies { get; set; }
public InterfaceResolverType InterfaceResolverType { get; set; } = InterfaceResolverType.Startup;

public DependencyTreeConfig(Assembly assembly, IConfiguration configuration = null, HashSet<string> skipAssemblies = null, string startupName = "Startup")
public DependencyTreeConfig(
Assembly assembly,
IConfiguration configuration = null)
{
Assembly = assembly ?? throw new ArgumentNullException(nameof(assembly));
Configuration = configuration;
SkipAssemblies = skipAssemblies;
StartupName = startupName;
}

public StartupInterfaceResolverConfig StartupConfig => new StartupInterfaceResolverConfig
Expand Down

0 comments on commit 40811dd

Please sign in to comment.