Lazy Func<T>

瀏覽次數:57 次
跳到第一則未讀訊息

shapper

未讀,
2010年9月12日 清晨7:58:232010/9/12
收件者:structuremap-users
Hello,

I have the following:

public class Foo {
private readonly Func<IPostService> _postServiceFactory;
public Foo(Func<IPostService> postServiceFactory) {
}
}

IPostService implements IService.

How can I set the Func<T> in Structure Map for all types of IService?

I think this is called Lazy Func<T> but I have been trying a few
options but it never compiles.

Thanks,
Miguel

Brian Chiasson

未讀,
2010年9月12日 上午8:41:252010/9/12
收件者:structure...@googlegroups.com
I am not sure there is an easy way to do this. You may have to create your own scanner if you have a lot of them, but I think this should work:
 
For<Func<IPostService>>().Use(() => /* Your func here */);

-Brian Chiasson
 

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


shapper

未讀,
2010年9月12日 上午10:35:492010/9/12
收件者:structuremap-users
Yes, I tried exactly that:

For<Func<IPostService>>().Use(() =>
ObjectFactory.GetInstance<PostService>());

Basically, I am checking the Structure Map Lazy Func<T> to deliver the
current PostService instance in use.

However, on the Foo class that Func is null.

What am I doing wrong?

Thank You,
Miguel
> > structuremap-us...@googlegroups.com<structuremap-users%2Bunsubs cr...@googlegroups.com>
> > .

Elliott O'Hara

未讀,
2010年9月12日 上午11:20:322010/9/12
收件者:structure...@googlegroups.com
For<Func<IPostService>>().Use(() => the actual function)

Also, don't use ObjectFactory in your Use method... use Use( container => container.SomeMethod)



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

Jeremy D. Miller

未讀,
2010年9月12日 上午11:30:152010/9/12
收件者:structure...@googlegroups.com
Better still, just register your T and Func<T> will work automatically if you're on 2.6+.
 
Jeremy D. Miller
The Shade Tree Developer
jeremy...@yahoo.com



From: Elliott O'Hara <elliot...@gmail.com>
To: structure...@googlegroups.com
Sent: Sun, September 12, 2010 10:20:32 AM
Subject: Re: [sm-users] Re: Lazy Func<T>

Elliott O'Hara

未讀,
2010年9月12日 上午11:37:382010/9/12
收件者:structure...@googlegroups.com
Thanks boss man!

it'll just use the greediest ctor?

Jeremy D. Miller

未讀,
2010年9月12日 上午11:39:082010/9/12
收件者:structure...@googlegroups.com
It just delegates to whatever is registered for the T, so yes.

Ctor selection will get more flexible in 3.0 -- whenever that happens;)
 
Sent: Sun, September 12, 2010 10:37:38 AM

Elliott O'Hara

未讀,
2010年9月12日 中午12:13:382010/9/12
收件者:structure...@googlegroups.com
Take your time... Don't get burned out!

Enjoy the non 100 degree days in ATX, take the kid to Zilker or something! It's beautiful here right now!

2.6x is working great for us.... 

Thanks for such a great tool man!

/E

shapper

未讀,
2010年9月12日 中午12:40:552010/9/12
收件者:structuremap-users
That is nice.

Thank You!

On Sep 12, 5:13 pm, "Elliott O'Hara" <elliott.oh...@gmail.com> wrote:
> Take your time... Don't get burned out!
>
> Enjoy the non 100 degree days in ATX, take the kid to Zilker or something!
> It's beautiful here right now!
>
> 2.6x is working great for us....
>
> Thanks for such a great tool man!
>
> /E
>
> On Sun, Sep 12, 2010 at 10:39 AM, Jeremy D. Miller
> <jeremydmil...@yahoo.com>wrote:
>
>
>
> > It just delegates to whatever is registered for the T, so yes.
>
> > Ctor selection will get more flexible in 3.0 -- whenever that happens;)
>
> > Jeremy D. Miller
> > The Shade Tree Developer <http://codebetter.com/blogs/jeremy.miller>
> > jeremydmil...@yahoo.com
>
> > ------------------------------
> > *From:* Elliott O'Hara <elliott.oh...@gmail.com>
> > *To:* structure...@googlegroups.com
> > *Sent:* Sun, September 12, 2010 10:37:38 AM
>
> > *Subject:* Re: [sm-users] Re: Lazy Func<T>
>
> > Thanks boss man!
>
> > it'll just use the greediest ctor?
>
> > On Sun, Sep 12, 2010 at 10:30 AM, Jeremy D. Miller <
> > jeremydmil...@yahoo.com> wrote:
>
> >> Better still, just register your T and Func<T> will work automatically if
> >> you're on 2.6+.
>
> >> Jeremy D. Miller
> >> The Shade Tree Developer <http://codebetter.com/blogs/jeremy.miller>
> >> jeremydmil...@yahoo.com
>
> >> ------------------------------
> >> *From:* Elliott O'Hara <elliott.oh...@gmail.com>
> >> *To:* structure...@googlegroups.com
> >> *Sent:* Sun, September 12, 2010 10:20:32 AM
> >> *Subject:* Re: [sm-users] Re: Lazy Func<T>
>
> >> For<Func<IPostService>>().Use(() => the actual function)
>
> >> Also, don't use ObjectFactory in your Use method... use Use( container =>
> >> container.SomeMethod)
>
> >>> > > structuremap-us...@googlegroups.com<structuremap-users%2Bunsubs cr...@googlegroups.com><structuremap-users%2Bunsubs
回覆所有人
回覆作者
轉寄
0 則新訊息