-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
when publishing a delegate or class with missing dependencies, hiro will throw a ConstructorNotFound exception #2
Comments
Hiro throws a ConstructorNotFoundException whenever a dependency is not found and this behavior is done by design. The reason why Hiro can't find a constructor on your sample Procedure delegate is that the constructor signature looks like this in IL:
The first parameter required by the delegate has to be the target object instance, and the second parameter is the System.IntPtr pointer that points to the method that you want to execute. In this case, Hiro will automatically throw the ConstructorNotFoundException because it doesn't know how to pass in an object instance and the given method pointer. The only workaround for this issue is to tell Hiro that you want to resolve the delegate at runtime, and you can do that by using the DependencyMap.AddDeferredService() method: var map = new DependencyMap(); Once you have the deferred service in place, you'll have to implement a custom IMicroContainer instance and chain it to the compiled container's NextContainer property so that Hiro will forward its request for a Procedure delegate to the next container: var yourContainer = yourMap.CreateContainer(); // Use the container just like you normally would use it |
Reposting from the comment on the closed pull request:
If you add these classes without using my modifications to ConstructorResolver.cs the Delegate.cs declaration produces several errors through your unit tests including my own. (this in my opinion is an actual bug, a delegate declaration is always complete, the compiler takes care of its dependencies) Update: on thinking a bit harder a delegate is a way to have a short service (i.e. a single method interface), however could they register themselves as defferred by default? Otherwise we have to configure potentially many services by hand on each map loader, in other words conventions stops working. I can't find how to filter missing constructor parameters without messing with the source. |
var map1 = new DependencyMap(); var combinedMap = map1 + map2; var combinedContainer = combinedMap.CreateContainer(); Try that out and let me know if that helps. On Fri, May 27, 2011 at 4:54 AM, juancastrodlc <
|
in the sample assembly add a simple delegate
public delegate void Procedure();
Hiro attempts to find a constructor and will fail
also when adding a class to the sample assembly
public interface ISomeInterface{}
public SomeClass:ISomeInterface
{
public SomeClass(Type missingDependency){}
}
will throw the same error.
Is this by design or is it a Bug?
If it is I'm working on the patch.
Greetings.
The text was updated successfully, but these errors were encountered: