code sweep

This commit is contained in:
Daniel Clark
2022-12-10 16:11:07 +00:00
parent 4f243eba2e
commit 0da4a37173
84 changed files with 2040 additions and 2104 deletions
@@ -1,43 +1,42 @@
using System.Diagnostics.CodeAnalysis;
namespace Toolkit.Foundation
namespace Toolkit.Framework.Foundation;
public class TemplateFactory : ITemplateFactory
{
public class TemplateFactory : ITemplateFactory
private readonly Dictionary<object, object> cache = new();
private readonly ITemplateDescriptorProvider provider;
private readonly IServiceFactory serviceFactory;
public TemplateFactory(ITemplateDescriptorProvider provider,
IServiceFactory serviceFactory)
{
private readonly Dictionary<object, object> cache = new();
this.provider = provider;
this.serviceFactory = serviceFactory;
}
private readonly ITemplateDescriptorProvider provider;
private readonly IServiceFactory serviceFactory;
public TemplateFactory(ITemplateDescriptorProvider provider,
IServiceFactory serviceFactory)
public virtual object? Create([MaybeNull] object? data)
{
if (data is null)
{
this.provider = provider;
this.serviceFactory = serviceFactory;
return null;
}
public virtual object? Create([MaybeNull] object? data)
if (cache.TryGetValue(data, out object? template))
{
if (data is null)
{
return null;
}
if (cache.TryGetValue(data, out object? template))
{
return template;
}
if (provider.Get(data.GetType()) is ITemplateDescriptor descriptor)
{
template = serviceFactory.Create(descriptor.TemplateType);
if (template is ICache cache)
{
this.cache[data] = cache;
}
}
return template;
}
if (provider.Get(data.GetType()) is ITemplateDescriptor descriptor)
{
template = serviceFactory.Create(descriptor.TemplateType);
if (template is ICache cache)
{
this.cache[data] = cache;
}
}
return template;
}
}
}