Re: [sm-users] Structure Map violates the constraint of type parameter 'CONCRETETYPE'

163 views
Skip to first unread message

Jeremy D. Miller

unread,
Nov 20, 2012, 9:05:21 AM11/20/12
to structure...@googlegroups.com
I'm guessing that this line is your problem:


For<IActionInvoker>().Use<InjectingActionInvoker>();



That error message is telling you that InjectingActionInvoker does not implement IActionInvoker, but I'm not sure how it would even be possible to compile the code if it's wrong.  Did you do something funky in deployment where you might have mismatched assemblies?

On Nov 20, 2012, at 1:19 AM, Deepak Agarwal <deepak....@gmail.com> wrote:

I have a web application developed in ASP.NET 2010. I have used the Dependency Injection with StructureMap in ASP.NET MVC. I'm trying to get started with Structure Map.  This code is working on another machine but didn't run on my machine.

I've built a simple boot strapper, but when I run the website I get the following error:

    StructureMap.Configuration.DSL.Expressions.CreatePluginFamilyExpression`1[System.Web.Mvc.IActionInvoker].Use: type argument 'TestWebsite.Web.Controllers.Factories.InjectingActionInvoker' violates the constraint of type parameter 'CONCRETETYPE'.


Code Block

public static void ConfigureStructureMap()
    {
        ObjectFactory.Initialize(x =>
        {
            //registry per assembly recommended
            x.AddRegistry<WebRegistry>();
            x.AddRegistry<ServiceRegistry>();
            x.AddRegistry<SHARE.Data.DataRegistry>();
        });

        //if a class needs configuring on load then this is done here. Inherit from IStartUpTask
        ObjectFactory.GetAllInstances<IStartUpTask>()
            .Where(x => x.IsEnabled).ToList()
            .ForEach(t => t.Configure());

        //This checks all is well.  Not ideal to do in application_start though cause of calls to request object....
        //ObjectFactory.AssertConfigurationIsValid();
    }


  public class WebRegistry : Registry
    {
        public WebRegistry()
        {
         For<IFormsAuthentication>    ().Use<FormsAuthenticationService>();
         For<IAuthentication>().Use<BasicMembership>();
                     Scan(x =>
            {
                x.AssemblyContainingType<IStartUpTask>();
                x.AddAllTypesOf<IStartUpTask>();
                x.WithDefaultConventions();
            });

            For<IActionInvoker>().Use<InjectingActionInvoker>();
            SetAllProperties(c =>
            {
                c.OfType<IActionInvoker>();
                c.WithAnyTypeFromNamespaceContainingType<UserService>(); //our services
                c.WithAnyTypeFromNamespaceContainingType<AdminCookies>(); //cookie services
            });

        }

Could anyone please suggest on this issue. how it could be resolved? I am really getting troubled with it and need to resolve it asap. Any help would be greatly appreciated.

Thanks

Deepak


--
You received this message because you are subscribed to the Google Groups "structuremap-users" group.
To post to this group, send email to structure...@googlegroups.com.
To unsubscribe from this group, send email to structuremap-us...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/structuremap-users/-/Qp1hoewSMdIJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages