31 lines
1.3 KiB
C#
31 lines
1.3 KiB
C#
using OwofGames.GodotLume;
|
|
|
|
namespace GodotHostTest.AetherBind;
|
|
|
|
public static class BuilderExtensions
|
|
{
|
|
public static Builder AddValueProvider<TValueType, TSourceScope, TDestinationScope>(this Builder builder)
|
|
where TValueType : class
|
|
where TSourceScope : RootScope
|
|
where TDestinationScope : TSourceScope
|
|
{
|
|
var valueProvider = new ValueProvider<TValueType>();
|
|
return builder
|
|
// add the setter to the source scope
|
|
.AddScoped<IValueSetter<TValueType>, IValueSetter<TValueType>, TSourceScope>(Builder.NoDependencies,
|
|
_ => valueProvider.Setter)
|
|
// add the getter to the destination scope
|
|
.AddScoped<IValueGetter<TValueType>, IValueGetter<TValueType>, TDestinationScope>(Builder.NoDependencies,
|
|
_ => valueProvider.Getter)
|
|
// add a factory to automatically extract TValueType from the IValueGetter<TValueType>
|
|
.AddScoped<TValueType, TValueType, TDestinationScope>(_ => [typeof(IValueGetter<TValueType>)],
|
|
provider => provider.Get<IValueGetter<TValueType>>().Value);
|
|
}
|
|
|
|
public static Builder AddValueProvider<TValueType, TScope>(this Builder builder)
|
|
where TValueType : class
|
|
where TScope : RootScope
|
|
{
|
|
return builder.AddValueProvider<TValueType, TScope, TScope>();
|
|
}
|
|
} |