No Default Instance Defined When Registering With AddAllTypesOf

276 views
Skip to first unread message

roend

unread,
Feb 10, 2010, 5:01:38 PM2/10/10
to structuremap-users
I'm getting a "No Default Instance Defined...(StructureMap Exception
Code: 202)" when trying to get all instances of a type that was
registered with AddAllTypesOf.

Here's my registry:

public class MyRegistry : Registory
{

}

Jeremy D. Miller

unread,
Feb 10, 2010, 5:04:10 PM2/10/10
to structure...@googlegroups.com
I think you're missing something from your question;)

Do Container.WhatDoIHave() on your container / ObjectFactory.  If StructureMap picks up more than 1 concrete type for the plugin type, it will NOT choose either as the default instance for that plugin type.

See this:  http://structuremap.sourceforge.net/ScanningAssemblies.htm#section2
 
Jeremy D. Miller
The Shade Tree Developer
jeremy...@yahoo.com



From: roend <roe...@gmail.com>
To: structuremap-users <structure...@googlegroups.com>
Sent: Wed, February 10, 2010 4:01:38 PM
Subject: [sm-users] No Default Instance Defined When Registering With AddAllTypesOf
--
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-users+unsub...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/structuremap-users?hl=en.


roend

unread,
Feb 10, 2010, 5:05:21 PM2/10/10
to structuremap-users
I'm getting a "No Default Instance Defined...(StructureMap Exception
Code: 202)" when trying to get all instances of a type that was
registered with AddAllTypesOf.

Here's my registry:

public class MyRegistry : Registry
{
public MyRegistry()
{
Scan(config =>
{
config.TheCallingAssembly();
config.AddAllTypesOf<IMyType>().NameBy(t =>
t.FullName);
});
}
}

And here's how I'm trying to access it:
foreach(var myType in ObjectFactory.GetAllInstances<IMyType>()
{
...

The exception happens when trying to iterate on the first item in the
collection.
Here's the relevant stack trace:

[StructureMapException: StructureMap Exception Code: 202
No Default Instance defined for PluginFamily
Rrc.Core.Data.Filters.IActiveUserVisibleDataFilter, Rrc.Core.Data,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]
StructureMap.BuildSession.<.ctor>b__0(Type t) +239
StructureMap.Util.Cache`2.get_Item(KEY key) +224
StructureMap.BuildSession.CreateInstance(Type pluginType) +16
StructureMap.BuildSession.GetInstance() +48
StructureMap.BuildSession.<GetAllInstances>b__8(Instance x) +63


Am I doing something wrong here?

roend

unread,
Feb 10, 2010, 5:05:49 PM2/10/10
to structuremap-users
Sorry for the double post

Jeremy D. Miller

unread,
Feb 10, 2010, 5:08:37 PM2/10/10
to structure...@googlegroups.com
Have you registered a default for .IActiveUserVisibleDataFilter?  One of your concrete types of IMyType apparently depends on IActiveUserVisibleDataFilter it its constructor.

From: roend <roe...@gmail.com>
To: structuremap-users <structure...@googlegroups.com>
Sent: Wed, February 10, 2010 4:05:49 PM
Subject: [sm-users] Re: No Default Instance Defined When Registering With AddAllTypesOf

roend

unread,
Feb 10, 2010, 5:45:48 PM2/10/10
to structuremap-users
IActiveUserVisibleDataFilter is IMyType.

Sorry for the confusion. I was trying to show a simple example of
what is happening.

On Feb 10, 5:08 pm, "Jeremy D. Miller" <jeremydmil...@yahoo.com>
wrote:


> Have you registered a default for .IActiveUserVisibleDataFilter?  One of your concrete types of IMyType apparently depends on IActiveUserVisibleDataFilter it its constructor.
>
>  Jeremy D. Miller
> The Shade Tree Developer

> jeremydmil...@yahoo.com
>
> ________________________________
> From: roend <roen...@gmail.com>

> To unsubscribe from this group, send email to structuremap-us...@googlegroups.com.

Jeremy D. Miller

unread,
Feb 10, 2010, 6:27:16 PM2/10/10
to structure...@googlegroups.com
Do you have some concrete type of IActiveUserVisibleDataFilter that takes in another IActiveUserVisibleDataFilter object as a parameter?

You're getting that error because *something* in your container registration that's that interface or a child of that interface has a dependency on IActiveUserVisibleDataFilter and StructureMap doesn't know which one is the *default* for that interface.

 
Jeremy D. Miller
The Shade Tree Developer
jeremy...@yahoo.com



From: roend <roe...@gmail.com>
To: structuremap-users <structure...@googlegroups.com>
Sent: Wed, February 10, 2010 4:45:48 PM
> To unsubscribe from this group, send email to structuremap-users+unsub...@googlegroups.com.

> For more options, visit this group athttp://groups.google.com/group/structuremap-users?hl=en.

--
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-users+unsub...@googlegroups.com.

roend

unread,
Feb 10, 2010, 8:49:00 PM2/10/10
to structuremap-users
I have a small test project that shows a better example of what I'm
trying to do. Is there a way for me to upload a file here?

On Feb 10, 6:27 pm, "Jeremy D. Miller" <jeremydmil...@yahoo.com>
wrote:


> Do you have some concrete type of IActiveUserVisibleDataFilter that takes in another IActiveUserVisibleDataFilter object as a parameter?
>
> You're getting that error because *something* in your container registration that's that interface or a child of that interface has a dependency on IActiveUserVisibleDataFilter and StructureMap doesn't know which one is the *default* for that interface.
>
>  Jeremy D. Miller
> The Shade Tree Developer

> > To unsubscribe from this group, send email to structuremap-us...@googlegroups.com.


> > For more options, visit this group athttp://groups.google.com/group/structuremap-users?hl=en.
>
> --
> 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.

Jeremy D. Miller

unread,
Feb 10, 2010, 8:55:46 PM2/10/10
to structure...@googlegroups.com
You can just attach it to the email.

 
Jeremy D. Miller
The Shade Tree Developer
jeremy...@yahoo.com



From: roend <roe...@gmail.com>
To: structuremap-users <structure...@googlegroups.com>
Sent: Wed, February 10, 2010 7:49:00 PM
> > To unsubscribe from this group, send email to structuremap-users+unsub...@googlegroups.com.

> > For more options, visit this group athttp://groups.google.com/group/structuremap-users?hl=en.
>
> --
> 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-users+unsub...@googlegroups.com.

> For more options, visit this group athttp://groups.google.com/group/structuremap-users?hl=en.

--
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-users+unsub...@googlegroups.com.

Nathan Roe

unread,
Feb 10, 2010, 9:01:27 PM2/10/10
to structure...@googlegroups.com
Example attached

To unsubscribe from this group, send email to structuremap-us...@googlegroups.com.
StructureMapTest.zip

Jeremy D. Miller

unread,
Feb 10, 2010, 9:31:45 PM2/10/10
to structure...@googlegroups.com
Well, good news and bad news.  You hit a bug in StructureMap 2.6.1 that I've already patched in the trunk.

The good news, all you need to do right now to make this work is change the code like this:

    public class MyParentClassRegistry : Registry
    {
        public MyParentClassRegistry()
        {
            // Use this code instead.  StructureMap will inject all IMyClass by default
            For<IMyParentClass>().Use<MyParentClass>();


            // Hide this
            //For<IMyParentClass>().Use(c => new MyParentClass(c.GetAllInstances<IMyClass>()));
        }
    }

You do know that you only need one Registry, right?


From: Nathan Roe <roe...@gmail.com>
To: structure...@googlegroups.com
Sent: Wed, February 10, 2010 8:01:27 PM
Subject: Re: [sm-users] Re: No Default Instance Defined When Registering With AddAllTypesOf

Nathan Roe

unread,
Feb 10, 2010, 10:18:24 PM2/10/10
to structure...@googlegroups.com
Thanks for the help.  Actually the reason that I'm doing it this way, is that MyParentClass actually has another constructor argument that is a named instance.  Is there any way to get around this problem if I have to manually fill in that parameter?

Jeremy D. Miller

unread,
Feb 10, 2010, 10:24:45 PM2/10/10
to structure...@googlegroups.com
as long as you don't explicitly specify the argument for the enumerable type you're good to go.  It isn't like Rhino Mocks where it's all or nothing.
Sent: Wed, February 10, 2010 9:18:24 PM

Nathan Roe

unread,
Feb 11, 2010, 12:53:25 AM2/11/10
to structure...@googlegroups.com
How do you do that in a For<>().Use() statement?

Jeremy D. Miller

unread,
Feb 11, 2010, 8:02:08 AM2/11/10
to structure...@googlegroups.com
For<>().Use<Foo>().******

where ***** is Ctor<IService>().Is()

For<>.Use<> returns an object that represents the object construction and provides all the chained methods you need to change the name, setup interceptors, or override constructor / setter arguments.
Sent: Wed, February 10, 2010 11:53:25 PM
Reply all
Reply to author
Forward
0 new messages