新增 FlowScope Git 包雏形
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace FlowScope.Container
|
||||
{
|
||||
public static class GeneratedFactories
|
||||
{
|
||||
private static readonly Dictionary<Type, Func<Container, object>> Factories = new Dictionary<Type, Func<Container, object>>();
|
||||
|
||||
public static void Register<TImplementation>(Func<Container, TImplementation> factory)
|
||||
{
|
||||
if (factory == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(factory));
|
||||
}
|
||||
|
||||
Factories[typeof(TImplementation)] = c => factory(c);
|
||||
}
|
||||
|
||||
public static bool TryGetFactory(Type implementationType, out Func<Container, object> factory)
|
||||
{
|
||||
if (implementationType == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(implementationType));
|
||||
}
|
||||
|
||||
return Factories.TryGetValue(implementationType, out factory);
|
||||
}
|
||||
|
||||
public static void RegisterAssembly(Container container)
|
||||
{
|
||||
if (container == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(container));
|
||||
}
|
||||
|
||||
foreach (var pair in Factories)
|
||||
{
|
||||
container.RegisterFactory(pair.Key, pair.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user