Is this a bug?

2 views
Skip to first unread message

epitka

unread,
Oct 5, 2009, 8:43:49 PM10/5/09
to structuremap-users
I am experimenting with using SM in MVP framework to do some auto-
wiring. So in bootstraper I define following:

x.ForRequestedType<IProjectList>
().TheDefaultIsConcreteType<ProjectList>();

and then in a constructor of the view I do following

_presenter = ObjectFactory.With(this)
.GetInstance<MetaProjectListPresenter>();

What happens is that constructor gets called twice. This is
experimental code and idea is that IView would have generic parameters
so that the base view could wire all this, without having to specify
this code in every view like this.

_presenter = ObjectFactory.With(this)
.GetInstance<TPresenterImpl>();


However "With" without generic parameter news an instance of "this"
instead of using the one provided as parameter. Is this a bug, and is
there workaround? Thanks in advance.

Jeremy D. Miller

unread,
Oct 5, 2009, 8:46:14 PM10/5/09
to structure...@googlegroups.com
Not a bug.  Watch your generics.

_presenter = ObjectFactory.With<IView>(this)
                        .GetInstance<MetaProjectListPresenter>();
 
Without the generic parameter it uses the concrete type of the view and ends up creating a second view.

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



From: epitka <exptra...@yahoo.com>
To: structuremap-users <structure...@googlegroups.com>
Sent: Monday, October 5, 2009 7:43:49 PM
Subject: [sm-users] Is this a bug?

epitka

unread,
Oct 5, 2009, 8:55:12 PM10/5/09
to structuremap-users
Darn it. Is there a way to have it not new up, or some other
workaround. Thanks for a very quick answer. BTW, I've used SM for two
days only and this thing rocks man.

On Oct 5, 7:46 pm, "Jeremy D. Miller" <jeremydmil...@yahoo.com> wrote:
> Not a bug.  Watch your generics.
>
> _presenter = ObjectFactory.With<IView>(this)
>                         .GetInstance<MetaProjectListPresenter>();
>
> Without the generic parameter it uses the concrete type of the view and ends up creating a second view.
>
> Jeremy D. Miller
> The Shade Tree Developer
> jeremydmil...@yahoo.com
>
> ________________________________
> From: epitka <exptrade2...@yahoo.com>

Jeremy D. Miller

unread,
Oct 5, 2009, 9:00:04 PM10/5/09
to structure...@googlegroups.com
What exactly is getting "new-ed" up twice?

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



From: epitka <exptra...@yahoo.com>
To: structuremap-users <structure...@googlegroups.com>
Sent: Monday, October 5, 2009 7:55:12 PM
Subject: [sm-users] Re: Is this a bug?

epitka

unread,
Oct 5, 2009, 9:08:25 PM10/5/09
to structuremap-users
The instance of "this". The current instance that is calling
ObjectFactory... This is continuation of my question from two-three
days ago http://groups.google.com/group/structuremap-users/browse_thread/thread/16697c88951531cb?hl=en

In MVP with webforms I have a view that needs to create a presenter,
and instance of the view has to be provided to the presenter. There
are other dependencies (service and automapper) but these are static
and are defined in the bootstrap. So basically WebForm view gets
instantiated twice.


On Oct 5, 8:00 pm, "Jeremy D. Miller" <jeremydmil...@yahoo.com> wrote:
> What exactly is getting "new-ed" up twice?
>
>  Jeremy D. Miller
> The Shade Tree Developer

Jeremy D. Miller

unread,
Oct 5, 2009, 9:12:31 PM10/5/09
to structure...@googlegroups.com
Gotcha, and it is because you didn't specify the interface type of the view.

Just curious, but why are you still doing WebForms?  All this stuff (DI/IoC, TDD, etc.) is higher friction with WebForms.

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



From: epitka <exptra...@yahoo.com>
To: structuremap-users <structure...@googlegroups.com>
Sent: Monday, October 5, 2009 8:08:25 PM

epitka

unread,
Oct 5, 2009, 9:14:34 PM10/5/09
to structuremap-users
To be more precise, SM news up instance of the view once, even though
I am providing it in the constructor. Don't know much about SM but I
would think, if I provide instance in the parameter, it would use that
one, rather then finding the type and newing it up.


On Oct 5, 8:08 pm, epitka <exptrade2...@yahoo.com> wrote:
> The instance of "this". The current instance that is calling
> ObjectFactory...  This is continuation of my question from two-three
> days agohttp://groups.google.com/group/structuremap-users/browse_thread/threa...

epitka

unread,
Oct 5, 2009, 9:31:32 PM10/5/09
to structuremap-users
I am developing a tool that is geared for the framework that is stuck
in the webforms. Most of the stuff will be re-used in MVC version that
will run stand-alone. I actually worked with MVC from the very
begining (Preview 3), but I find it that not very many companies are
switching to MVC yet.

On Oct 5, 8:12 pm, "Jeremy D. Miller" <jeremydmil...@yahoo.com> wrote:
> Gotcha, and it is because you didn't specify the interface type of the view.
>
> Just curious, but why are you still doing WebForms?  All this stuff (DI/IoC, TDD, etc.) is higher friction with WebForms.
>
>  Jeremy D. Miller
> The Shade Tree Developer
> jeremydmil...@yahoo.com
>
> ________________________________
> From: epitka <exptrade2...@yahoo.com>
> To: structuremap-users <structure...@googlegroups.com>
> Sent: Monday, October 5, 2009 8:08:25 PM
> Subject: [sm-users] Re: Is this a bug?
>
> The instance of "this". The current instance that is calling
> ObjectFactory...  This is continuation of my question from two-three
> days agohttp://groups.google.com/group/structuremap-users/browse_thread/threa...
Reply all
Reply to author
Forward
0 new messages