Skip to content

Commit

Permalink
fix: 🐛 Fix missing exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Klein committed May 10, 2023
1 parent f68dcab commit a1ab011
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions Source/Composition/Extensions/NodeExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,32 @@

namespace GoDough.Composition.Extensions {
public static class NodeCompositionExtensions {
public static void WireNode(this Node node) {
Func<Attribute, bool> isInjectionAttribute = x =>
x.GetType().IsAssignableFrom(typeof(InjectAttribute));
public static Node WireNode(this Node node) {
try {
Func<Attribute, bool> isInjectionAttribute = x =>
x.GetType().IsAssignableFrom(typeof(InjectAttribute));

var props = node.GetType().GetProperties();
var propsWithInjection = props
.Where(x => x.GetCustomAttributes()
.Any(isInjectionAttribute))
.Select(prop => new {
Property = prop,
InjectionInfo = prop.GetCustomAttributes().First(isInjectionAttribute) as InjectAttribute
});
var props = node.GetType().GetProperties();
var propsWithInjection = props
.Where(x => x.GetCustomAttributes()
.Any(isInjectionAttribute))
.Select(prop => new {
Property = prop,
InjectionInfo = prop.GetCustomAttributes().First(isInjectionAttribute) as InjectAttribute
});

foreach(var injectedPropertyInfo in propsWithInjection) {
var propertyReturnType = injectedPropertyInfo.Property.GetMethod.ReturnType;
var serviceInstance = AppHost.Instance.Application.Services.GetService(propertyReturnType);
foreach(var injectedPropertyInfo in propsWithInjection) {
var propertyReturnType = injectedPropertyInfo.Property.GetMethod.ReturnType;
var serviceInstance = AppHost.Instance.Application.Services.GetService(propertyReturnType);

injectedPropertyInfo.Property
.SetValue(node, serviceInstance);
injectedPropertyInfo.Property
.SetValue(node, serviceInstance);
}

return node;
} catch (Exception ex) {
GD.PrintErr(ex.ToString());
throw ex;
}
}
}
Expand Down

0 comments on commit a1ab011

Please sign in to comment.