mirror of https://github.com/AMT-Cheif/Stylet.git
StyletIoC: Don't cache expressions by default
This in turn causes ConstructorInfos to be cached, and those are pretty expensive.
This commit is contained in:
parent
9b1b1308b6
commit
95a9995746
|
@ -109,8 +109,15 @@ namespace StyletIoC.Internal.Creators
|
|||
|
||||
var completeExpression = this.CompleteExpressionFromCreator(creator, registrationContext);
|
||||
|
||||
Interlocked.CompareExchange(ref this.creationExpression, completeExpression, null);
|
||||
return this.creationExpression;
|
||||
if (StyletIoCContainer.CacheGeneratedExpressions)
|
||||
{
|
||||
Interlocked.CompareExchange(ref this.creationExpression, completeExpression, null);
|
||||
return this.creationExpression;
|
||||
}
|
||||
else
|
||||
{
|
||||
return completeExpression;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,8 +60,15 @@ namespace StyletIoC.Internal.Registrations
|
|||
var listNew = Expression.New(listCtor, Expression.Constant(instanceExpressions.Length));
|
||||
Expression list = instanceExpressions.Any() ? (Expression)Expression.ListInit(listNew, instanceExpressions) : listNew;
|
||||
|
||||
Interlocked.CompareExchange(ref this.expression, list, null);
|
||||
return this.expression;
|
||||
if (StyletIoCContainer.CacheGeneratedExpressions)
|
||||
{
|
||||
Interlocked.CompareExchange(ref this.expression, list, null);
|
||||
return this.expression;
|
||||
}
|
||||
else
|
||||
{
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,5 +11,17 @@ namespace StyletIoC
|
|||
/// Name of the assembly in which abstract factories are built. Use in [assembly: InternalsVisibleTo(StyletIoCContainer.FactoryAssemblyName)] to allow factories created by .ToAbstractFactory() to access internal types
|
||||
/// </summary>
|
||||
public static readonly string FactoryAssemblyName = "StyletIoCFactory";
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether generated Expressions are cached, or resolved anew each time.
|
||||
/// Setting to true may speed up the compilation phase in the case where one type is required by many other types.
|
||||
/// However, it will cause loads of ConstructorInfos to be cached forever, and they're actually pretty expensive to hold on to.
|
||||
/// </summary>
|
||||
public static bool CacheGeneratedExpressions { get; set; }
|
||||
|
||||
static StyletIoCContainer()
|
||||
{
|
||||
CacheGeneratedExpressions = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue