<commit_before>---
layout: post
title: "Dependency Injection and events"
date: 2013-09-06 08:38 UTC
tags: [Dependency Injection]
---
{% include JB/setup %}

<div id="post">
	<p>
		<em>Overview of articles about Dependency Injection and events.</em>
	</p>
	<p>
		One of my readers, <NAME>, asks me about subscribing to events in the constructor of a class using Constructor Injection:
	</p>
	<blockquote>
		<p>
			I want to register to a plain old .NET event of a dependency that is supplied via constructor injection. I read your book "<a href="http://amzn.to/12p90MG">DI in .NET</a>" and in it you mention that injection constructors should be simple and not perform any other work than guarding for null values and assigning the dependencies to (read-only) fields. I also read on your blog that <a href="http://blog.ploeh.dk/2011/03/03/InjectionConstructorsshouldbesimple">this is only a pattern and might be broken gently if the need would arise</a>.
		</p>
		<p><commit_msg>Added description to Twitter card<commit_after>---
layout: post
title: "Dependency Injection and events"
description: "Overview of articles about Dependency Injection and events."
date: 2013-09-06 08:38 UTC
tags: [Dependency Injection]
---
{% include JB/setup %}

<div id="post">
	<p>
		<em>{{ page.description }}</em>
	</p>
	<p>
		One of my readers, <NAME>, asks me about subscribing to events in the constructor of a class using Constructor Injection:
	</p>
	<blockquote>
		<p>
			I want to register to a plain old .NET event of a dependency that is supplied via constructor injection. I read your book "<a href="http://amzn.to/12p90MG">DI in .NET</a>" and in it you mention that injection constructors should be simple and not perform any other work than guarding for null values and assigning the dependencies to (read-only) fields. I also read on your blog that <a href="http://blog.ploeh.dk/2011/03/03/InjectionConstructorsshouldbesimple">this is only a pattern and might be broken gently if the need would arise</a>.
		</p>
		<p>
{'fraction_non_alphanumeric': 0.10327706057596822, 'fraction_numerical': 0.023833167825223437, 'mean_word_length': 4.193298969072165, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3222618', 'n_tokens_mistral': 650, 'n_tokens_neox': 588, 'n_words': 275}