Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Please help with ScanAssemblies
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  17 messages - Expand all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
jdc  
View profile  
 More options Sep 11 2008, 10:17 am
From: jdc <jdcrutch...@spiffworks.com>
Date: Thu, 11 Sep 2008 07:17:16 -0700 (PDT)
Local: Thurs, Sep 11 2008 10:17 am
Subject: Please help with ScanAssemblies
I'm trying to understand Registry and ScanAssemblies.  Here's what
I've put together to test with:

Web application with a simple "Hello World" type page.
Web app references Core assembly.
Core assembly contains IWidget interface containing nothing but a Name
property.
Three additional assemblies "Red", "Green", and "Blue" contain
RedWidget, BlueWidget, and GreenWidget which are very skeletal
implementations of IWidget that set the Name property to a name passed
in through the constructor.

So, each color assembly has a registry that looks like this:

    public class RedRegistry : StructureMap.Configuration.DSL.Registry
    {
        protected override void configure()
        {

StructureMap.StructureMapConfiguration.AddInstanceOf<CoreStuff.IWidget>()
                .UsingConcreteType<RedWidget>()
                .WithName("RedWidget")
                .WithProperty("name").EqualTo("Red Widget");
        }
    }

To use a widget in the web app I use code like this:

    CoreStuff.IWidget redWidget =
StructureMap.ObjectFactory.GetNamedInstance<CoreStuff.IWidget>("RedWidget") ;

So, if I put this in my app startup things work:

    StructureMap.StructureMapConfiguration.AddRegistry(new
RedNamespace.RedRegistry());
    StructureMap.StructureMapConfiguration.AddRegistry(new
GreenNamespace.GreenRegistry());
    StructureMap.StructureMapConfiguration.AddRegistry(new
BlueNamespace.BlueRegistry());

I was under the impression I could do this, but it doesn't seem to
work:

    StructureMap.StructureMapConfiguration.ScanAssemblies()
        .IncludeAssemblyContainingType<RedNamespace.RedRegistry>()
        .IncludeAssemblyContainingType<GreenNamespace.GreenRegistry>()
        .IncludeAssemblyContainingType<BlueNamespace.BlueRegistry>();

Whenever I try to get a widget from the container, I get the "Could
not find Instance named RedWidget for plugin type CoreStuff.IWidget"
message.

Actually, what I'd rather do is something like this to get all
assemblies that happen to contain IWidget implementations:

    StructureMap.StructureMapConfiguration.ScanAssemblies()
        .IncludeAssemblyContainingType<CoreStuff.IWidget>()

but I'd be happy at this point just to get the simple case where I
know the registries in advance.

Any idea what I'm missing?  I've done Google searches out the wazoo
without any luck so far.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jdc  
View profile  
 More options Sep 11 2008, 11:28 am
From: jdc <jdcrutch...@spiffworks.com>
Date: Thu, 11 Sep 2008 08:28:30 -0700 (PDT)
Local: Thurs, Sep 11 2008 11:28 am
Subject: Re: Please help with ScanAssemblies
A few other things I tried...  For simplification, I removed the
"name" parameter so the widgets have a parameterless constructor.  I
also changed the configuration method of the registries to look like
this:

StructureMap.StructureMapConfiguration.BuildInstancesOf<IWidget>()
                .TheDefault.Is.OfConcreteType<GreenWidget>();

I tried this in my startup routine also - which resulted in all of the
registries being called as I could see through the debugger:

           StructureMap.ObjectFactory.Configure(registry =>
registry.ScanAssemblies()
            .IncludeAssemblyContainingType<RedNamespace.RedRegistry>()
            .IncludeAssemblyContainingType<GreenNamespace.GreenRegistry>()
            .IncludeAssemblyContainingType<BlueNamespace.BlueRegistry>());

Still get an error 202 from StructureMap when I try to do a
GetInstance<IWidget>() though.  Even though I watched it in the
debugger run through those BuildInstancesOf calls at startup.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chad Myers  
View profile  
 More options Sep 11 2008, 11:31 am
From: "Chad Myers" <chad.my...@gmail.com>
Date: Thu, 11 Sep 2008 10:31:49 -0500
Local: Thurs, Sep 11 2008 11:31 am
Subject: Re: [sm-users] Please help with ScanAssemblies

Try something like this:
protected override void configure()
{

 ForRequestedType<CoreStuff.IWidget>().TheDefaultIsConcreteType<RedWidget>() ...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jdc  
View profile  
 More options Sep 11 2008, 11:38 am
From: jdc <jdcrutch...@spiffworks.com>
Date: Thu, 11 Sep 2008 08:38:45 -0700 (PDT)
Local: Thurs, Sep 11 2008 11:38 am
Subject: Re: Please help with ScanAssemblies
That didn't work either.  After my configuration methods run (and I've
whittled it down to just one) the ObjectFactory.WhatDoIHave method
returns this:

=========================================================================== ================================
Configuration Sources:

0)   Registry:  StructureMap.Configuration.DSL.Registry,StructureMap
1)   Registry:  StructureMap.Configuration.DSL.Registry,StructureMap

===================================
PluginType     Name     Description
===================================

Then if I re-run (after the 202 exception, but without restarting the
app) I get this:

=========================================================================== ================================
Configuration Sources:

0)   Registry:  StructureMap.Configuration.DSL.Registry,StructureMap
1)   Registry:  StructureMap.Configuration.DSL.Registry,StructureMap

====================================================
PluginType                      Name     Description
----------------------------------------------------
CoreStuff.IWidget,CoreStuff
Built by:  StructureMap.Pipeline.BuildPolicy

====================================================

This is confusing the hell out of me.  Do I need the configuration XML
file or attributes?  I was under the impression that using
ScanAssemblies with the Registry classes I wouldn't need those.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jdc  
View profile  
 More options Sep 11 2008, 11:46 am
From: jdc <jdcrutch...@spiffworks.com>
Date: Thu, 11 Sep 2008 08:46:54 -0700 (PDT)
Local: Thurs, Sep 11 2008 11:46 am
Subject: Re: Please help with ScanAssemblies
Ok, I'm getting closer.  If, within the Registry configure method, I
use something like this:

    ObjectFactory.SetDefault<IWidget, GreenWidget>()

then I can instantiate one later.  It's like calling methods on
StructureMapConfiguration doesn't apply to ObjectFactory.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jeremy D. Miller  
View profile  
 More options Sep 11 2008, 11:50 am
From: "Jeremy D. Miller" <jeremydmil...@yahoo.com>
Date: Thu, 11 Sep 2008 08:50:38 -0700 (PDT)
Local: Thurs, Sep 11 2008 11:50 am
Subject: Re: [sm-users] Re: Please help with ScanAssemblies

STOP!

Don't ever make any calls to ObjectFactory within a Registry.  I think I'm killing off that SetDefault method right now because it can only cause problems.

Give me the lunch hour and I'll respond to the ScanAssemblies question.

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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jdc  
View profile  
 More options Sep 12 2008, 9:08 am
From: jdc <jdcrutch...@spiffworks.com>
Date: Fri, 12 Sep 2008 06:08:59 -0700 (PDT)
Local: Fri, Sep 12 2008 9:08 am
Subject: Re: Please help with ScanAssemblies
I banged around on this a little more yesterday evening and still no
luck.  I think I'm using the latest trunk (last update I pulled down
was from September 2).  Maybe I'm misunderstanding what ScanAssemblies
is supposed to do?

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jimmy Bogard  
View profile  
 More options Sep 12 2008, 9:11 am
From: "Jimmy Bogard" <jimmy.bog...@gmail.com>
Date: Fri, 12 Sep 2008 08:11:31 -0500
Local: Fri, Sep 12 2008 9:11 am
Subject: Re: [sm-users] Please help with ScanAssemblies

Don't use still have to use a scanner?  I think you might still need to have
the .With<DefaultConventionScanner>() part.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jdc  
View profile  
 More options Sep 12 2008, 9:27 am
From: jdc <jdcrutch...@spiffworks.com>
Date: Fri, 12 Sep 2008 06:27:15 -0700 (PDT)
Local: Fri, Sep 12 2008 9:27 am
Subject: Re: Please help with ScanAssemblies
I did have some success using a scanner, but I'd rather avoid that.
What I'm looking for is some way to drop a DLL into the directory and
have the existing call to ScanAssemblies find the Registry within it
and fire off the configure method.  I can actually get that far.  I
step through in the debugger and see the configure method running.
The trouble is, the registrations I do within that method don't
"stick".  However, if I do a StructureMapConfiguration.AddRegistry(new
TheRegistry()) for each one, then it works. Of course then I'm back to
knowing in advance what my registries are...

I suppose I could try creating an ITypeScanner that, when it finds
something assignable to IRegistry, calls
StructureMapConfiguration.AddRegistry on it.  I'll probably try that
next.

I was just under the impression that ScanAssemblies was supposed to do
that already.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jeremy D. Miller  
View profile  
 More options Sep 12 2008, 9:54 am
From: "Jeremy D. Miller" <jeremydmil...@yahoo.com>
Date: Fri, 12 Sep 2008 06:54:25 -0700 (PDT)
Local: Fri, Sep 12 2008 9:54 am
Subject: Re: [sm-users] Re: Please help with ScanAssemblies

ScanAssemblies has to be explicitly told which assemblies to scan.  I've always been leery of any kind of behavior that you wouldn't expect.

You've got a couple options, but they both involve writing your own code:

1.) Set aside an "extensions" folder of some type directly under the main application folder.  In the bootstrapping code, find all the assembly files in that directory, and add each to ScanAssemblies().AddAssembly( assembly name).  This is the approach that my team is going to take for our extensibility strategy, but we aren't going to work on that until at least October.

2.) Go with an Xml file at an expected location that lists the assemblies to load

ScanAssemblies will pick up any registry classes in assemblies (plus the attribute configuration, but I'd recommend the Registry approach), but it has to be told which assemblies to load and scan.

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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jdc  
View profile  
 More options Sep 12 2008, 10:05 am
From: jdc <jdcrutch...@spiffworks.com>
Date: Fri, 12 Sep 2008 07:05:43 -0700 (PDT)
Local: Fri, Sep 12 2008 10:05 am
Subject: Re: Please help with ScanAssemblies
Thanks Jeremy.  The problem I'm having though isn't that the
registries aren't being scanned.  I can watch in the debugger that the
configure methods are called.  However, the statements in them don't
seem to have any effect.  I still get 202 errors when I try
GetInstance.  It does work if I used
StructureMapConfiguration.AddRegistry on each of them though.  In both
cases I can watch through the debugger and see configure getting
called on each registry, but when it's kicked off from ScanAssemblies
the configuration doesn't stick.

I also noticed that using ScanAssemblies, the actual running of the
configure methods is delayed until the first call to GetInstance.
Probably because ScanAssemblies is really just creating an
expression.  Is it possible that my ObjectFactory is getting into some
state where it doesn't allow changes by the time the actual scan runs?


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chad Myers  
View profile  
 More options Sep 12 2008, 10:15 am
From: "Chad Myers" <chad.my...@gmail.com>
Date: Fri, 12 Sep 2008 09:15:38 -0500
Local: Fri, Sep 12 2008 10:15 am
Subject: RE: [sm-users] Re: Please help with ScanAssemblies
So you're looking for like a start-up plug-in discovery type functionality?

-c


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jdc  
View profile  
 More options Sep 12 2008, 10:25 am
From: jdc <jdcrutch...@spiffworks.com>
Date: Fri, 12 Sep 2008 07:25:30 -0700 (PDT)
Local: Fri, Sep 12 2008 10:25 am
Subject: Re: Please help with ScanAssemblies
I was just trying to work through your example at
http://www.lostechies.com/blogs/chad_myers/archive/2008/07/17/structu....
Assuming I could get that working, I was going to try something like
what Jeremy mentioned about creating a special directory for
assemblies to be auto-scanned for registries then use some reflection
magic to add each one to the scan.

Trouble is, I can't even get the simple case to work.  Scan assemblies
seems to have no trouble finding the registries and running their
configure methods.  It's just that any configuration done by those
registries doesn't seem to actually happen.  Only adding the registry
directly with StructureMapConfiguration.AddRegistry actually works.

On Sep 12, 9:15 am, "Chad Myers" <chad.my...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jeremy D. Miller  
View profile  
 More options Sep 12 2008, 10:38 am
From: "Jeremy D. Miller" <jeremydmil...@yahoo.com>
Date: Fri, 12 Sep 2008 07:38:27 -0700 (PDT)
Local: Fri, Sep 12 2008 10:38 am
Subject: Re: [sm-users] Re: Please help with ScanAssemblies

Any chance you can send me the code?  That functionality has quite a bit of unit test coverage, so I think there's something else going on.

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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jdc  
View profile  
 More options Sep 12 2008, 10:57 am
From: jdc <jdcrutch...@spiffworks.com>
Date: Fri, 12 Sep 2008 07:57:45 -0700 (PDT)
Local: Fri, Sep 12 2008 10:57 am
Subject: Re: Please help with ScanAssemblies
Sure thing.  I sent the project to your Yahoo account.  Thanks for
having a look at this.

On Sep 12, 9:38 am, "Jeremy D. Miller" <jeremydmil...@yahoo.com>
wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jdc  
View profile  
 More options Sep 15 2008, 2:16 pm
From: jdc <jdcrutch...@spiffworks.com>
Date: Mon, 15 Sep 2008 11:16:41 -0700 (PDT)
Local: Mon, Sep 15 2008 2:16 pm
Subject: Re: Please help with ScanAssemblies
FYI for anyone having a similar problem:

Jeremy was good enough to have a look at my code and point me in the
right direction.  Apparently I should NOT have been doing this from
within a registry:

StructureMap.StructureMapConfiguration.AddInstanceOf<CoreStuff.IWidget>()
                .UsingConcreteType<RedWidget>()
                .WithName("RedWidget")
                .WithProperty("name").EqualTo("Red Widget");

I should have done this:

            BuildInstancesOf<CoreStuff.IWidget>()
                .TheDefault.Is.OfConcreteType<RedWidget>()
                .WithName("RedWidget")
                .WithProperty("name").EqualTo("Red Widget");

Thanks to everyone that helped track this down.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jimmy Bogard  
View profile  
 More options Sep 15 2008, 7:22 pm
From: "Jimmy Bogard" <jimmy.bog...@gmail.com>
Date: Mon, 15 Sep 2008 18:22:40 -0500
Local: Mon, Sep 15 2008 7:22 pm
Subject: Re: [sm-users] Re: Please help with ScanAssemblies

Obsoleting the SMC stuff should fix this too...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google