Wrox Programmer Forums
BOOK: Professional ASP.NET MVC 4
This is the forum to discuss the Wrox book Professional ASP.NET MVC 4 by Jon Galloway, Phil Haack, Brad Wilson, K. Scott Allen; ISBN: 978-1-118-34846-8
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET MVC 4 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 April 15th, 2014, 09:12 AM
Registered User
Join Date: Apr 2005
Posts: 352
Thanks: 14
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rupen
Default Chapter 12: Dependency Injection


The code at page # 299 is as follows:

public interface IMessagingService
void SendMessage();
public class EmailService : IMessagingService
public void SendMessage() { ... }
public class NotificationSystem
private IMessagingService svc;
public NotificationSystem()
svc = new EmailService();
public void InterestingEventHappened()
I think the constructor of NotificationSystem should not create a new object of EmailService. Instead, it should be IMessagingService.
Please justify if not so.
Old April 21st, 2014, 11:28 PM
Friend of Wrox
Join Date: Feb 2014
Posts: 136
Thanks: 1
Thanked 10 Times in 10 Posts


you can not create an instance of IMessagingService, it was declared as an interface. Since EmailService inherits the IMessagingService interface the private member variable can hold an instance of an EmailService. Interfaces are a contract for other classes to fullfill through inheritance they do not contain concrete code and can't be instantiated.

Last edited by mmorgan30; April 25th, 2014 at 06:29 PM.. Reason: typo

Similar Threads
Thread Thread Starter Forum Replies Last Post
Chap 12 - Security, SQL Injection vulnerability illustration kenj BOOK: PHP and MySQL: Create-Modify-Reuse ISBN: 978-0-470-19242-9 0 November 12th, 2010 05:01 PM
Generics chapter 12 difficult chapter i found ...? Larryz C# 2005 1 July 4th, 2007 09:40 PM
Errors on Chapter 12 example(12.8) sonnie ASP.NET 2.0 Professional 2 June 7th, 2006 10:55 AM
dependency files m002864 Crystal Reports 0 July 7th, 2004 02:56 PM

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