Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > Other ASP.NET > BOOK: Professional ASP.NET Design Patterns
|
BOOK: Professional ASP.NET Design Patterns
This is the forum to discuss the Wrox book Professional ASP.NET Design Patterns by Scott Millett; ISBN: 978-0-470-29278-5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET Design Patterns section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 18th, 2010, 11:37 PM
Authorized User
 
Join Date: Jan 2006
Posts: 13
Thanks: 6
Thanked 1 Time in 1 Post
Default IoC container for ProductService without registry entry?

I am studying Chapter 8 at the moment and am reading the MVP section where you have the following in bootstrapper:

publicclassControllerRegistry : Registry
{
public ControllerRegistry()
{
ForRequestedType<
ICategoryRepository>().TheDefault.Is.OfConcreteType<CategoryRepository>();
ForRequestedType<
IProductRepository>().TheDefault.Is.OfConcreteType<ProductRepository>();
ForRequestedType<
IPageNavigator>().TheDefault.Is.OfConcreteType<PageNavigator>();
ForRequestedType<
IBasket>().TheDefault.Is.OfConcreteType<WebBasket>();
}
}

And I am also seeing code like this

protectedvoid Page_Init(object sender, EventArgs e)
{
_presenter =
newProductDetailPresenter(this, ObjectFactory.GetInstance<ProductService>(),
ObjectFactory.GetInstance<IBasket>(),
ObjectFactory.GetInstance<IPageNavigator>());
}

see the bolded line above.

My question is: since we don't have an entry for ProductService, how can we get IoC to pass a reference this way?

Shouldn't we instead have

_presenter = newProductDetailPresenter(this,
newProductService(
ObjectFactory.GetInstance<ICategoryRepository>(),

ObjectFactory.GetInstance<IProductRepository>()
),
....
....)



Is this explained anywhere in the book?

Thanks!
 
Old November 21st, 2010, 09:03 AM
elbandit's Avatar
Wrox Author
 
Join Date: May 2007
Posts: 107
Thanks: 10
Thanked 17 Times in 15 Posts
Default

Hi SamVan,

Hope you are still enjoying the book.

If you take a look at page 296 I mention how this is achieved using the order service sample code...

Quote:
You may have noticed that you didn’t explicitly register the OrderService type with StructureMap even though it was able to resolve it. This happens because StructureMap auto-wires the dependencies based on what it already has in its container. Auto-wiring your dependencies gives you the maximum benefit of using any type of container. Your client code can remain blissfully unaware of the concrete dependencies defined.


You can find more info on how structuremap does autowiring by reading the info on the structuremap project page -- http://structuremap.net/structuremap/AutoWiring.htm.

I hope this answers your questions.
Cheers
Scott
The Following User Says Thank You to elbandit For This Useful Post:
samvan (November 22nd, 2010)
 
Old November 22nd, 2010, 03:13 PM
Authorized User
 
Join Date: Jan 2006
Posts: 13
Thanks: 6
Thanked 1 Time in 1 Post
Default

yes, how could I miss that paragraph..... thanks Scott and I really enjoy reading your book!
 
Old November 22nd, 2010, 04:05 PM
elbandit's Avatar
Wrox Author
 
Join Date: May 2007
Posts: 107
Thanks: 10
Thanked 17 Times in 15 Posts
Default

No worries! Glad your still enjoying the book, let me know if you have any other questions, and it would be great if you could add your feedback in a review on amazon .

Cheers
Scott
 
Old November 25th, 2010, 01:56 AM
Authorized User
 
Join Date: Jan 2006
Posts: 13
Thanks: 6
Thanked 1 Time in 1 Post
Default

Scott,

I plan to write a review once I finish Part II of the book (Chapter 9). Thanks again for your support the past few weeks :)
 
Old November 25th, 2010, 01:39 PM
elbandit's Avatar
Wrox Author
 
Join Date: May 2007
Posts: 107
Thanks: 10
Thanked 17 Times in 15 Posts
Default

Fantastico! I really appreciate it, and no worries please ask as many questions as you want :0)

Cheers
Scott





Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the difference between AOP and IoC kotaiah Spring 0 September 6th, 2007 01:21 AM
Container Binding problem tany4u Javascript How-To 0 October 3rd, 2006 01:36 AM
what the heck is a container?[:D] lcsgeek General .NET 0 January 24th, 2005 12:56 PM
Name 'Container' is not declared. surendran ASP.NET 1.0 and 1.1 Professional 1 August 17th, 2004 10:33 AM
Form Container shortynelson General .NET 1 August 13th, 2004 01:27 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.