feat: new ValueProvider improvements and source generator.

This commit is contained in:
redglow
2026-07-20 11:06:35 +02:00
parent 036e4af431
commit c540b99eb6
12 changed files with 79 additions and 37 deletions
+8 -1
View File
@@ -5,18 +5,25 @@ 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);
_ => 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>();