Supposing I have a method GetAssemblies, which returns a list of assemblies, and a method called GetConventions, which returns a ConventionBuilder, I might compose my container like this:
CompositionHost container =
new ContainerConfiguration()
.WithAssemblies(
GetAssemblies(),
GetConventions())
.CreateContainer();
But I might also compose it like this:
CompositionHost container =
new ContainerConfiguration()
.WithAssemblies(GetAssemblies())
.WithDefaultConventions(GetConventions())
.CreateContainer();
Question: What is the difference, if any, between these two ways of doing it?
It is the word "default" in WithDefaultConventions that is throwing me. MSDN doesn't shed much light on what this means. If the method was simply called WithConventions, I wouldn't have given it a second thought.
Example methods below.
GetAssemblies:
private static IEnumerable<Assembly> GetAssemblies()
{
return new[]
{
typeof(FileQueue).Assembly,
typeof(LoggerExport).Assembly,
};
}
GetConventions:
private static ConventionBuilder GetConventions()
{
var conventionBuilder = new ConventionBuilder();
conventionBuilder
.ForType<OmsDbContext>()
.Export<OmsDbContext>()
.SelectConstructor(ctorInfos => ctorInfos.First())
.Shared("Boundary.UnitOfWork");
return conventionBuilder;
}
In your example, the two things should do the same. But, if you'd have WithAssemblies called multiple times, you could call WithDefaultConventions() only once to apply those conventions to the assemblies from all those calls. Otherwise you would have to provide the conventions each time as the second parameter to WithAssemblies() method to achieve the same effect.
Too bad you don't find much information on the Microsoft.Composition package from Microsoft itself.