Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do you make a Ninject Provider when the constructor of type is not known?
    text
    copied!<p>I decided to try to conjure up a container assembly to interact with FubuMVC. Well the cool part is that it pass all the test that the FubuMVC.Container.StructureMap assembly does. However, when I dropped it into the FubuSample. I received an activation error.</p> <p>The error is because in the provider for the behaviors I'm only calling a parameterless constructor to build behavior instances. That is unacceptable in real life it would seem.</p> <p>Here is how it is set up:</p> <pre><code>public class TestBehavior2 : IControllerActionBehavior { public IControllerActionBehavior InsideBehavior { get; set; } public IInvocationResult Result { get; set; } protected FubuConfiguration Configuration { get; set; } protected FubuConventions Conventions { get; set; } public TestBehavior2(FubuConventions conventions, FubuConfiguration config) { Conventions = conventions; Configuration = config; } public OUTPUT Invoke&lt;INPUT, OUTPUT&gt;(INPUT input, Func&lt;INPUT, OUTPUT&gt; func) where INPUT : class where OUTPUT : class { // Invocation stuff } } public class TestBehavior : IControllerActionBehavior { public IControllerActionBehavior InsideBehavior { get; set; } public IInvocationResult Result { get; set; } public OUTPUT Invoke&lt;INPUT, OUTPUT&gt;(INPUT input, Func&lt;INPUT, OUTPUT&gt; func) where INPUT : class where OUTPUT : class { // Invocation stuff } } </code></pre> <p>My Load method has these binding in it:</p> <pre><code>foreach (var actionConfig in _configuration.GetControllerActionConfigs()) { Bind(actionConfig.ControllerType).ToSelf(); Bind&lt;IControllerActionBehavior&gt;() .ToProvider(new BehaviorInstanceProvider(actionConfig)) .WhenParentNamed(actionConfig.UniqueID); Bind&lt;IControllerActionInvoker&gt;().To(actionConfig.InvokerType) .Named(actionConfig.UniqueID); } </code></pre> <p>In my provider's Create method is:</p> <pre><code>public object Create(IContext context) { var behavior = ConfigureInstance(context); foreach (var type in _config.GetBehaviors().Reverse()) { IControllerActionBehavior previousBehavior = behavior; behavior = (IControllerActionBehavior)Activator.CreateInstance(type); t.GetProperty(INSIDE_PROP_NAME).SetValue(behavior, temp, null); } return behavior; } </code></pre> <p>So my question is how should I set up to provider to create an instance of a service when all I don't know what the constructor will look like? Or rather if I use the ConstructorInfo to ascertain the constructor will Ninject inject the appropriate dependencies?</p> <p>This is using Ninject 2b, since FubuMvc requires CommonServiceLocator support. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload