Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Getting Started with Angular - Second edition - Second Edition

You're reading from  Getting Started with Angular - Second edition - Second Edition

Product type Book
Published in Feb 2017
Publisher Packt
ISBN-13 9781787125278
Pages 278 pages
Edition 2nd Edition
Languages
Author (1):
Minko Gechev Minko Gechev
Profile icon Minko Gechev

Table of Contents (16) Chapters

Getting Started with Angular Second Edition
Credits
Foreword
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
1. Get Going with Angular 2. The Building Blocks of an Angular Application 3. TypeScript Crash Course 4. Getting Started with Angular Components and Directives 5. Dependency Injection in Angular 6. Working with the Angular Router and Forms 7. Explaining Pipes and Communicating with RESTful Services 8. Tooling and Development Experience

Defining factories for instantiating services


Now, let's suppose that we want to create a complex object, for example, one that represents a Transport Layer Security (TLS) connection. A few of the properties of such an object are a socket, a set of crypto protocols, and a certificate. In the context of this problem, the features of the DI mechanism of Angular we have looked at so far might seem a bit limited.

For example, we might need to configure some of the properties of the TLSConnection class without coupling the process of its instantiation with all the configuration details (choose appropriate crypto algorithms, open the TCP socket over which we will establish the secure connection, and so on).

In this case, we can take advantage of the useFactory property of the provider's configuration object:

let injector = ReflectiveInjector.resolveAndCreate([ 
  { 
    provide: TLSConnection, 
    useFactory: (socket: Socket, certificate: Certificate, crypto: Crypto) 
      ...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}