PageRenderTime 55ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/src/packages/SimpleInjector.Extensions.1.5.0.12238/lib/net35/SimpleInjector.Extensions.xml

http://fluentjqgrid.codeplex.com
XML | 1776 lines | 1660 code | 116 blank | 0 comment | 0 complexity | fd91840dfcf29e54dc64196e1ec4eda1 MD5 | raw file
  1. <?xml version="1.0"?>
  2. <doc>
  3. <assembly>
  4. <name>SimpleInjector.Extensions</name>
  5. </assembly>
  6. <members>
  7. <member name="T:SimpleInjector.Extensions.DecoratorExtensions">
  8. <summary>
  9. Extension methods for applying decorators.
  10. </summary>
  11. </member>
  12. <member name="M:SimpleInjector.Extensions.DecoratorExtensions.RegisterDecorator(SimpleInjector.Container,System.Type,System.Type)">
  13. <summary>
  14. Ensures that the supplied <paramref name="decoratorType"/> decorator is returned, wrapping the
  15. original registered <paramref name="serviceType"/>, by injecting that service type into the
  16. constructor of the supplied <paramref name="decoratorType"/>. Multiple decorators may be applied
  17. to the same <paramref name="serviceType"/>. Decorators can be applied to both open, closed, and
  18. non-generic service types.
  19. </summary>
  20. <remarks>
  21. <para>
  22. The <b>RegisterDecorator</b> method works by hooking onto the container's
  23. <see cref="E:SimpleInjector.Container.ExpressionBuilt">ExpressionBuilt</see> event. This event fires after the
  24. <see cref="E:SimpleInjector.Container.ResolveUnregisteredType">ResolveUnregisteredType</see> event, which allows
  25. decoration of types that are resolved using unregistered type resolution. The
  26. <see cref="M:SimpleInjector.Extensions.OpenGenericRegistrationExtensions.RegisterOpenGeneric(SimpleInjector.Container,System.Type,System.Type)">RegisterOpenGeneric</see>
  27. extension method, for instance, hooks onto the <b>ResolveUnregisteredType</b>. This allows you to
  28. use <b>RegisterDecorator</b> on the same generic service type as <b>RegisterOpenGeneric</b>.
  29. </para>
  30. <para>
  31. Multiple decorators can be applied to the same service type. The order in which they are registered
  32. is the order they get applied in. This means that the decorator that gets registered first, gets
  33. applied first, which means that the next registered decorator, will wrap the first decorator, which
  34. wraps the original service type.
  35. </para>
  36. <para>
  37. The registered <paramref name="decoratorType"/> must have a single public constructor. Constructor
  38. injection will be used on that type, and although it may have many constructor arguments, it must
  39. have exactly one argument of the type of <paramref name="serviceType"/>, or an argument of type
  40. <see cref="T:System.Func`1"/> where <b>T</b> is <paramref name="serviceType"/>. An exception will be
  41. thrown when this is not the case.
  42. </para>
  43. <para>
  44. The registered <paramref name="decoratorType"/> may have a constructor with an argument of type
  45. <see cref="T:System.Func`1"/> where <b>T</b> is <paramref name="serviceType"/>. In this case, the
  46. will not inject the decorated <paramref name="serviceType"/> itself into the
  47. <paramref name="decoratorType"/> instance, but it will inject a <see cref="T:System.Func`1"/> that allows
  48. creating instances of the decorated type, according to the lifestyle of that type. This enables
  49. more advanced scenarios, such as executing the decorated types on a different thread, or executing
  50. decorated instance within a certain scope (such as a lifetime scope).
  51. </para>
  52. </remarks>
  53. <example>
  54. The following example shows the definition of a generic <b>ICommandHandler&lt;T&gt;</b> interface,
  55. a <b>CustomerMovedCommandHandler</b> implementing that interface, and a
  56. <b>ValidatorCommandHandlerDecorator&lt;T&gt;</b> that acts as a decorator for that interface.
  57. <code lang="cs"><![CDATA[
  58. using System.ComponentModel.DataAnnotations;
  59. using System.Diagnostics;
  60. using System.Linq;
  61. using Microsoft.VisualStudio.TestTools.UnitTesting;
  62. using SimpleInjector;
  63. using SimpleInjector.Extensions;
  64. public interface ICommandHandler<TCommand>
  65. {
  66. void Handle(TCommand command);
  67. }
  68. public class CustomerMovedCommand
  69. {
  70. [Required]
  71. public int CustomerId { get; set; }
  72. [Required]
  73. public Address Address { get; set; }
  74. }
  75. public class CustomerMovedCommandHandler
  76. : ICommandHandler<CustomerMovedCommand>
  77. {
  78. public void Handle(CustomerMovedCommand command)
  79. {
  80. // some logic
  81. }
  82. }
  83. // Decorator that validates commands before they get executed.
  84. public class ValidatorCommandHandlerDecorator<TCommand>
  85. : ICommandHandler<TCommand>
  86. {
  87. private readonly ICommandHandler<TCommand> decoratedHandler;
  88. private readonly Container container;
  89. public ValidatorCommandHandlerDecorator(
  90. ICommandHandler<TCommand> decoratedHandler,
  91. Container container)
  92. {
  93. this.decoratedHandler = decoratedHandler;
  94. this.container = container;
  95. }
  96. public void Handle(TCommand command)
  97. {
  98. this.Validate(command);
  99. this.decoratedHandler.Handle(command);
  100. }
  101. private void Validate(TCommand command)
  102. {
  103. var validationContext =
  104. new ValidationContext(command, this.container, null);
  105. Validator.ValidateObject(command, validationContext);
  106. }
  107. }
  108. // Decorator that measures the time it takes to execute a command.
  109. public class MonitoringCommandHandlerDecorator<TCommand>
  110. : ICommandHandler<TCommand>
  111. {
  112. private readonly ICommandHandler<TCommand> decoratedHandler;
  113. private readonly ILogger logger;
  114. public MonitoringCommandHandlerDecorator(
  115. ICommandHandler<TCommand> decoratedHandler,
  116. ILogger logger)
  117. {
  118. this.decoratedHandler = decoratedHandler;
  119. this.logger = logger;
  120. }
  121. public void Handle(TCommand command)
  122. {
  123. var watch = Stopwatch.StartNew();
  124. this.decoratedHandler.Handle(command);
  125. this.logger.Log(string.Format("{0} executed in {1} ms.",
  126. command.GetType().Name, watch.ElapsedMilliseconds));
  127. }
  128. }
  129. [TestMethod]
  130. public static void TestRegisterOpenGenericDecorator()
  131. {
  132. // Arrange
  133. var container = new Container();
  134. container.RegisterSingle<ILogger, DebugLogger>();
  135. // Search the given assembly and register all concrete types that
  136. // implement ICommandHandler<TCommand>.
  137. container.RegisterManyForOpenGeneric(typeof(ICommandHandler<>),
  138. typeof(ICommandHandler<>).Assembly);
  139. // Wrap all ICommandHandler<TCommand> service types with a decorator
  140. // that measures and logs the duration of that handler.
  141. container.RegisterDecorator(typeof(ICommandHandler<>),
  142. typeof(MonitoringCommandHandlerDecorator<>));
  143. // Wrap all ICommandHandler<TCommand> types (in this case it will
  144. // wrap the monitoring decorator), but only if the TCommand contains
  145. // any properties.
  146. container.RegisterDecorator(typeof(ICommandHandler<>),
  147. typeof(ValidatorCommandHandlerDecorator<>), context =>
  148. {
  149. var commandType = context.ServiceType.GetGenericArguments()[0];
  150. bool mustDecorate = commandType.GetProperties().Any();
  151. return mustDecorate;
  152. });
  153. // Act
  154. var handler =
  155. container.GetInstance<ICommandHandler<CustomerMovedCommand>>();
  156. // Assert
  157. Assert.IsInstanceOfType(handler,
  158. typeof(ValidatorCommandHandlerDecorator<CustomerMovedCommand>));
  159. }
  160. ]]></code>
  161. </example>
  162. <param name="container">The container to make the registrations in.</param>
  163. <param name="serviceType">The definition of the open generic service type that will
  164. be wrapped by the given <paramref name="decoratorType"/>.</param>
  165. <param name="decoratorType">The definition of the open generic decorator type that will
  166. be used to wrap the original service type.</param>
  167. <exception cref="T:System.ArgumentNullException">Thrown when either <paramref name="container"/>,
  168. <paramref name="serviceType"/>, or <paramref name="decoratorType"/> are null
  169. references.</exception>
  170. <exception cref="T:System.ArgumentException">Thrown when <paramref name="serviceType"/> is not
  171. an open generic type, when <paramref name="decoratorType"/> does not inherit from or implement
  172. <paramref name="serviceType"/>, when <paramref name="decoratorType"/> does not
  173. have a single public constructor, or when <paramref name="decoratorType"/> does not
  174. contain a constructor that has exactly one argument of type
  175. <paramref name="serviceType"/> or <see cref="T:System.Func`1"/> where <b>T</b> is
  176. <paramref name="serviceType"/>.</exception>
  177. </member>
  178. <member name="M:SimpleInjector.Extensions.DecoratorExtensions.RegisterDecorator(SimpleInjector.Container,System.Type,System.Type,System.Predicate{SimpleInjector.Extensions.DecoratorPredicateContext})">
  179. <summary>
  180. Ensures that the supplied <paramref name="decoratorType"/> decorator is returned when the supplied
  181. <paramref name="predicate"/> returns <b>true</b>, wrapping the original registered
  182. <paramref name="serviceType"/>, by injecting that service type into the constructor of the
  183. supplied <paramref name="decoratorType"/>. Multiple decorators may be applied to the same
  184. <paramref name="serviceType"/>. Decorators can be applied to both open, closed, and non-generic
  185. service types.
  186. </summary>
  187. <remarks>
  188. <para>
  189. The <b>RegisterOpenGenericDecorator</b> method works by hooking onto the container's
  190. <see cref="E:SimpleInjector.Container.ExpressionBuilt">ExpressionBuilt</see> event. This event fires after the
  191. <see cref="E:SimpleInjector.Container.ResolveUnregisteredType">ResolveUnregisteredType</see> event, which allows
  192. decoration of types that are resolved using unregistered type resolution. The
  193. <see cref="M:SimpleInjector.Extensions.OpenGenericRegistrationExtensions.RegisterOpenGeneric(SimpleInjector.Container,System.Type,System.Type)">RegisterOpenGeneric</see>
  194. extension method, for instance, hooks onto the <b>ResolveUnregisteredType</b>. This allows you to
  195. use <b>RegisterOpenGenericDecorator</b> on the same service type as <b>RegisterOpenGeneric</b>.
  196. </para>
  197. <para>
  198. Multiple decorators can be applied to the same service type. The order in which they are registered
  199. is the order they get applied in. This means that the decorator that gets registered first, gets
  200. applied first, which means that the next registered decorator, will wrap the first decorator, which
  201. wraps the original service type.
  202. </para>
  203. <para>
  204. The registered <paramref name="decoratorType"/> must have a single public constructor. Constructor
  205. injection will be used on that type, and although it may have many constructor arguments, it must
  206. have exactly one argument of the type of <paramref name="serviceType"/>, or an argument of type
  207. <see cref="T:System.Func`1"/> where <b>T</b> is <paramref name="serviceType"/>. An exception will be
  208. thrown when this is not the case.
  209. </para>
  210. <para>
  211. The registered <paramref name="decoratorType"/> may have a constructor with an argument of type
  212. <see cref="T:System.Func`1"/> where <b>T</b> is <paramref name="serviceType"/>. In this case, the
  213. will not inject the decorated <paramref name="serviceType"/> itself into the
  214. <paramref name="decoratorType"/> instance, but it will inject a <see cref="T:System.Func`1"/> that allows
  215. creating instances of the decorated type, according to the lifestyle of that type. This enables
  216. more advanced scenarios, such as executing the decorated types on a different thread, or executing
  217. decorated instance within a certain scope (such as a lifetime scope).
  218. </para>
  219. </remarks>
  220. <example>
  221. The following example shows the definition of a generic <b>ICommandHandler&lt;T&gt;</b> interface,
  222. a <b>CustomerMovedCommandHandler</b> implementing that interface, and a
  223. <b>ValidatorCommandHandlerDecorator&lt;T&gt;</b> that acts as a decorator for that interface.
  224. <code lang="cs"><![CDATA[
  225. using System.ComponentModel.DataAnnotations;
  226. using System.Diagnostics;
  227. using System.Linq;
  228. using Microsoft.VisualStudio.TestTools.UnitTesting;
  229. using SimpleInjector;
  230. using SimpleInjector.Extensions;
  231. public interface ICommandHandler<TCommand>
  232. {
  233. void Handle(TCommand command);
  234. }
  235. public class CustomerMovedCommand
  236. {
  237. [Required]
  238. public int CustomerId { get; set; }
  239. [Required]
  240. public Address Address { get; set; }
  241. }
  242. public class CustomerMovedCommandHandler
  243. : ICommandHandler<CustomerMovedCommand>
  244. {
  245. public void Handle(CustomerMovedCommand command)
  246. {
  247. // some logic
  248. }
  249. }
  250. // Decorator that validates commands before they get executed.
  251. public class ValidatorCommandHandlerDecorator<TCommand>
  252. : ICommandHandler<TCommand>
  253. {
  254. private readonly ICommandHandler<TCommand> decoratedHandler;
  255. private readonly Container container;
  256. public ValidatorCommandHandlerDecorator(
  257. ICommandHandler<TCommand> decoratedHandler,
  258. Container container)
  259. {
  260. this.decoratedHandler = decoratedHandler;
  261. this.container = container;
  262. }
  263. public void Handle(TCommand command)
  264. {
  265. this.Validate(command);
  266. this.decoratedHandler.Handle(command);
  267. }
  268. private void Validate(TCommand command)
  269. {
  270. var validationContext =
  271. new ValidationContext(command, this.container, null);
  272. Validator.ValidateObject(command, validationContext);
  273. }
  274. }
  275. // Decorator that measures the time it takes to execute a command.
  276. public class MonitoringCommandHandlerDecorator<TCommand>
  277. : ICommandHandler<TCommand>
  278. {
  279. private readonly ICommandHandler<TCommand> decoratedHandler;
  280. private readonly ILogger logger;
  281. public MonitoringCommandHandlerDecorator(
  282. ICommandHandler<TCommand> decoratedHandler,
  283. ILogger logger)
  284. {
  285. this.decoratedHandler = decoratedHandler;
  286. this.logger = logger;
  287. }
  288. public void Handle(TCommand command)
  289. {
  290. var watch = Stopwatch.StartNew();
  291. this.decoratedHandler.Handle(command);
  292. this.logger.Log(string.Format("{0} executed in {1} ms.",
  293. command.GetType().Name, watch.ElapsedMilliseconds));
  294. }
  295. }
  296. [TestMethod]
  297. public static void TestRegisterOpenGenericDecorator()
  298. {
  299. // Arrange
  300. var container = new Container();
  301. container.RegisterSingle<ILogger, DebugLogger>();
  302. // Search the given assembly and register all concrete types that
  303. // implement ICommandHandler<TCommand>.
  304. container.RegisterManyForOpenGeneric(typeof(ICommandHandler<>),
  305. typeof(ICommandHandler<>).Assembly);
  306. // Wrap all ICommandHandler<TCommand> service types with a decorator
  307. // that measures and logs the duration of that handler.
  308. container.RegisterOpenGenericDecorator(typeof(ICommandHandler<>),
  309. typeof(MonitoringCommandHandlerDecorator<>));
  310. // Wrap all ICommandHandler<TCommand> types (in this case it will
  311. // wrap the monitoring decorator), but only if the TCommand contains
  312. // any properties.
  313. container.RegisterOpenGenericDecorator(typeof(ICommandHandler<>),
  314. typeof(ValidatorCommandHandlerDecorator<>), context =>
  315. {
  316. var commandType = context.ServiceType.GetGenericArguments()[0];
  317. bool mustDecorate = commandType.GetProperties().Any();
  318. return mustDecorate;
  319. });
  320. // Act
  321. var handler =
  322. container.GetInstance<ICommandHandler<CustomerMovedCommand>>();
  323. // Assert
  324. Assert.IsInstanceOfType(handler,
  325. typeof(ValidatorCommandHandlerDecorator<CustomerMovedCommand>));
  326. }
  327. ]]></code>
  328. </example>
  329. <param name="container">The container to make the registrations in.</param>
  330. <param name="serviceType">The definition of the open generic service type that will
  331. be wrapped by the given <paramref name="decoratorType"/>.</param>
  332. <param name="decoratorType">The definition of the open generic decorator type that will
  333. be used to wrap the original service type.</param>
  334. <param name="predicate">The predicate that determines whether the
  335. <paramref name="decoratorType"/> must be applied to a service type.</param>
  336. <exception cref="T:System.ArgumentNullException">Thrown when either <paramref name="container"/>,
  337. <paramref name="serviceType"/>, <paramref name="decoratorType"/>, or
  338. <paramref name="predicate"/> are null references.</exception>
  339. <exception cref="T:System.ArgumentException">Thrown when <paramref name="serviceType"/> is not
  340. an open generic type, when <paramref name="decoratorType"/> does not inherit from or
  341. implement <paramref name="serviceType"/>, when <paramref name="decoratorType"/>
  342. does not have a single public constructor, or when <paramref name="decoratorType"/> does
  343. not contain a constructor that has exactly one argument of type
  344. <paramref name="serviceType"/> or <see cref="T:System.Func`1"/> where <b>T</b> is
  345. <paramref name="serviceType"/>.</exception>
  346. </member>
  347. <member name="M:SimpleInjector.Extensions.DecoratorExtensions.RegisterSingleDecorator(SimpleInjector.Container,System.Type,System.Type)">
  348. <summary>
  349. Ensures that a single instance of the supplied <paramref name="decoratorType"/> decorator is
  350. returned, wrapping the original registered <paramref name="serviceType"/>, by injecting that
  351. service type into the constructor of the supplied <paramref name="decoratorType"/>. Multiple
  352. decorators may be applied to the same <paramref name="serviceType"/>. Decorators can be applied
  353. to both open, closed, and non-generic service types.
  354. </summary>
  355. <remarks>
  356. <para>
  357. This method ensures that a single instance of the supplied <paramref name="decoratorType"/> is
  358. returned, no matter what the lifestyle of the wrapped service type is. Use with care, because the
  359. wrapped service type will also become a singleton. This method is especially useful when use for
  360. injecting <see cref="T:System.Func`1"/> factory methods, which will allow the wrapped service type to get
  361. it's own lifestyle back.
  362. </para>
  363. <para>
  364. Please see the <see cref="M:SimpleInjector.Extensions.DecoratorExtensions.RegisterDecorator(SimpleInjector.Container,System.Type,System.Type)">RegisterDecorator</see> method
  365. for more information.
  366. </para>
  367. </remarks>
  368. <param name="container">The container to make the registrations in.</param>
  369. <param name="serviceType">The definition of the open generic service type that will
  370. be wrapped by the given <paramref name="decoratorType"/>.</param>
  371. <param name="decoratorType">The definition of the open generic decorator type that will
  372. be used to wrap the original service type.</param>
  373. <exception cref="T:System.ArgumentNullException">Thrown when either <paramref name="container"/>,
  374. <paramref name="serviceType"/>, or <paramref name="decoratorType"/> are null
  375. references.</exception>
  376. <exception cref="T:System.ArgumentException">Thrown when <paramref name="serviceType"/> is not
  377. an open generic type, when <paramref name="decoratorType"/> does not inherit from or implement
  378. <paramref name="serviceType"/>, when <paramref name="decoratorType"/> does not
  379. have a single public constructor, or when <paramref name="decoratorType"/> does not
  380. contain a constructor that has exactly one argument of type
  381. <paramref name="serviceType"/> or <see cref="T:System.Func`1"/> where <b>T</b> is
  382. <paramref name="serviceType"/>.</exception>
  383. </member>
  384. <member name="M:SimpleInjector.Extensions.DecoratorExtensions.RegisterSingleDecorator(SimpleInjector.Container,System.Type,System.Type,System.Predicate{SimpleInjector.Extensions.DecoratorPredicateContext})">
  385. <summary>
  386. Ensures that the supplied <paramref name="decoratorType"/> decorator is returned when the supplied
  387. <paramref name="predicate"/> returns <b>true</b>, wrapping the original registered
  388. <paramref name="serviceType"/>, by injecting that service type into the constructor of the
  389. supplied <paramref name="decoratorType"/>. Multiple decorators may be applied to the same
  390. <paramref name="serviceType"/>. Decorators can be applied to both open, closed, and non-generic
  391. service types.
  392. </summary>
  393. <remarks>
  394. <para>
  395. This method ensures that a single instance of the supplied <paramref name="decoratorType"/> is
  396. returned, no matter what the lifestyle of the wrapped service type is. Use with care, because the
  397. wrapped service type will also become a singleton. This method is especially useful when use for
  398. injecting <see cref="T:System.Func`1"/> factory methods, which will allow the wrapped service type to get
  399. it's own lifestyle back.
  400. </para>
  401. <para>
  402. Please see the
  403. <see cref="M:SimpleInjector.Extensions.DecoratorExtensions.RegisterDecorator(SimpleInjector.Container,System.Type,System.Type,System.Predicate{SimpleInjector.Extensions.DecoratorPredicateContext})">RegisterDecorator</see>
  404. method for more information.
  405. </para>
  406. </remarks>
  407. <param name="container">The container to make the registrations in.</param>
  408. <param name="serviceType">The definition of the open generic service type that will
  409. be wrapped by the given <paramref name="decoratorType"/>.</param>
  410. <param name="decoratorType">The definition of the open generic decorator type that will
  411. be used to wrap the original service type.</param>
  412. <param name="predicate">The predicate that determines whether the
  413. <paramref name="decoratorType"/> must be applied to a service type.</param>
  414. <exception cref="T:System.ArgumentNullException">Thrown when either <paramref name="container"/>,
  415. <paramref name="serviceType"/>, <paramref name="decoratorType"/>, or
  416. <paramref name="predicate"/> are null references.</exception>
  417. <exception cref="T:System.ArgumentException">Thrown when <paramref name="serviceType"/> is not
  418. an open generic type, when <paramref name="decoratorType"/> does not inherit from or
  419. implement <paramref name="serviceType"/>, when <paramref name="decoratorType"/>
  420. does not have a single public constructor, or when <paramref name="decoratorType"/> does
  421. not contain a constructor that has exactly one argument of type
  422. <paramref name="serviceType"/> or <see cref="T:System.Func`1"/> where <b>T</b> is
  423. <paramref name="serviceType"/>.</exception>
  424. </member>
  425. <member name="T:SimpleInjector.Extensions.DecoratorPredicateContext">
  426. <summary>
  427. An instance of this type will be supplied to the <see cref="T:System.Predicate`1"/>
  428. delegate that is that is supplied to the
  429. <see cref="M:SimpleInjector.Extensions.DecoratorExtensions.RegisterDecorator(SimpleInjector.Container,System.Type,System.Type,System.Predicate{SimpleInjector.Extensions.DecoratorPredicateContext})">RegisterDecorator</see>
  430. overload that takes this delegate. This type contains information about the decoration that is about
  431. to be applied and it allows users to examine the given instance to see whether the decorator should
  432. be applied or not.
  433. </summary>
  434. </member>
  435. <member name="P:SimpleInjector.Extensions.DecoratorPredicateContext.ServiceType">
  436. <summary>
  437. Gets the closed generic service type for which the decorator is about to be applied. The original
  438. service type will be returned, even if other decorators have already been applied to this type.
  439. </summary>
  440. <value>The closed generic service type.</value>
  441. </member>
  442. <member name="P:SimpleInjector.Extensions.DecoratorPredicateContext.ImplementationType">
  443. <summary>
  444. Gets the type of the implementation that is created by the container and for which the decorator
  445. is about to be applied. The original implementation type will be returned, even if other decorators
  446. have already been applied to this type. Please not that the implementation type can not always be
  447. determined. In that case the closed generic service type will be returned.
  448. </summary>
  449. <value>The implementation type.</value>
  450. </member>
  451. <member name="P:SimpleInjector.Extensions.DecoratorPredicateContext.AppliedDecorators">
  452. <summary>
  453. Gets the list of the types of decorators that have already been applied to this instance.
  454. </summary>
  455. <value>The applied decorators.</value>
  456. </member>
  457. <member name="P:SimpleInjector.Extensions.DecoratorPredicateContext.Expression">
  458. <summary>
  459. Gets the current <see cref="P:SimpleInjector.Extensions.DecoratorPredicateContext.Expression"/> object that describes the intention to create a new
  460. instance with its currently applied decorators.
  461. </summary>
  462. <value>The current expression that is about to be decorated.</value>
  463. </member>
  464. <member name="T:SimpleInjector.Extensions.Decorators.IDecoratableEnumerable">
  465. <summary>
  466. An IDecoratableEnumerable is a special enumerable that can be used more efficiently by the container
  467. to apply decorators to, with the biggest noticable difference that the registered predicate, will be
  468. checked for each service in the collection.
  469. </summary>
  470. </member>
  471. <member name="T:SimpleInjector.Extensions.Decorators.DecoratorExpressionInterceptor">
  472. <summary>
  473. Hooks into the building process and adds a decorator if needed.
  474. </summary>
  475. </member>
  476. <member name="T:SimpleInjector.Extensions.GenericArgumentFinder">
  477. <summary>
  478. Allows retrieving the concrete types of the generic type arguments of that must be used to create a
  479. closed generic implementation of a given open generic implementation, based on on the concrete
  480. arguments of the given closed base type.
  481. </summary>
  482. </member>
  483. <member name="T:SimpleInjector.Extensions.GenericArgumentFinder.ArgumentMapping">
  484. <summary>
  485. A map containing a generic argument (such as T) and the concrete type (such as Int32) that it
  486. represents.
  487. </summary>
  488. </member>
  489. <member name="M:SimpleInjector.Extensions.GenericArgumentFinder.ArgumentMapping.System#IEquatable{SimpleInjector#Extensions#GenericArgumentFinder#ArgumentMapping}#Equals(SimpleInjector.Extensions.GenericArgumentFinder.ArgumentMapping)">
  490. <summary>Implements equality. Needed for doing LINQ distinct operations.</summary>
  491. <param name="other">The other to compare to.</param>
  492. <returns>True or false.</returns>
  493. </member>
  494. <member name="M:SimpleInjector.Extensions.GenericArgumentFinder.ArgumentMapping.GetHashCode">
  495. <summary>Overrides the default hash code. Needed for doing LINQ distinct operations.</summary>
  496. <returns>An 32 bit integer.</returns>
  497. </member>
  498. <member name="T:SimpleInjector.Extensions.GenericArgumentFinder.TypeConstraintValidator">
  499. <summary>
  500. Allows validating an ArgumentMapping.
  501. </summary>
  502. </member>
  503. <member name="T:SimpleInjector.Extensions.GenericDecoratorExtensions">
  504. <summary>
  505. Extension methods for applying generic decorators.
  506. </summary>
  507. </member>
  508. <member name="M:SimpleInjector.Extensions.GenericDecoratorExtensions.RegisterOpenGenericDecorator(SimpleInjector.Container,System.Type,System.Type)">
  509. <summary>
  510. Ensures that a closed generic version of the supplied <paramref name="openGenericDecorator"/>
  511. decorator is returned, wrapping the original closed generic version of the registered
  512. <paramref name="openGenericServiceType"/>, by injecting that service type into the constructor
  513. of the supplied <paramref name="openGenericDecorator"/>. Multiple decorators may be applied to the
  514. same <paramref name="openGenericServiceType"/>.
  515. </summary>
  516. <remarks>
  517. <para>
  518. The <b>RegisterOpenGenericDecorator</b> method works by hooking onto the container's
  519. <see cref="E:SimpleInjector.Container.ExpressionBuilt">ExpressionBuilt</see> event. This event fires after the
  520. <see cref="E:SimpleInjector.Container.ResolveUnregisteredType">ResolveUnregisteredType</see> event, which allows
  521. decoration of types that are resolved using unregistered type resolution. The
  522. <see cref="M:SimpleInjector.Extensions.OpenGenericRegistrationExtensions.RegisterOpenGeneric(SimpleInjector.Container,System.Type,System.Type)">RegisterOpenGeneric</see>
  523. extension method, for instance, hooks onto the <b>ResolveUnregisteredType</b>. This allows you to
  524. use <b>RegisterOpenGenericDecorator</b> on the same service type as <b>RegisterOpenGeneric</b>.
  525. </para>
  526. <para>
  527. Multiple decorators can be applied to the same service type. The order in which they are registered
  528. is the order they get applied in. This means that the decorator that gets registered first, gets
  529. applied first, which means that the next registered decorator, will wrap the first decorator, which
  530. wraps the original service type.
  531. </para>
  532. </remarks>
  533. <example>
  534. The following example shows the definition of a generic <b>ICommandHandler&lt;T&gt;</b> interface,
  535. a <b>CustomerMovedCommandHandler</b> implementing that interface, and a
  536. <b>ValidatorCommandHandlerDecorator&lt;T&gt;</b> that acts as a decorator for that interface.
  537. <code lang="cs"><![CDATA[
  538. using System.ComponentModel.DataAnnotations;
  539. using System.Diagnostics;
  540. using System.Linq;
  541. using Microsoft.VisualStudio.TestTools.UnitTesting;
  542. using SimpleInjector;
  543. using SimpleInjector.Extensions;
  544. public interface ICommandHandler<TCommand>
  545. {
  546. void Handle(TCommand command);
  547. }
  548. public class CustomerMovedCommand
  549. {
  550. [Required]
  551. public int CustomerId { get; set; }
  552. [Required]
  553. public Address Address { get; set; }
  554. }
  555. public class CustomerMovedCommandHandler
  556. : ICommandHandler<CustomerMovedCommand>
  557. {
  558. public void Handle(CustomerMovedCommand command)
  559. {
  560. // some logic
  561. }
  562. }
  563. // Decorator that validates commands before they get executed.
  564. public class ValidatorCommandHandlerDecorator<TCommand>
  565. : ICommandHandler<TCommand>
  566. {
  567. private readonly ICommandHandler<TCommand> decoratedHandler;
  568. private readonly Container container;
  569. public ValidatorCommandHandlerDecorator(
  570. ICommandHandler<TCommand> decoratedHandler,
  571. Container container)
  572. {
  573. this.decoratedHandler = decoratedHandler;
  574. this.container = container;
  575. }
  576. public void Handle(TCommand command)
  577. {
  578. this.Validate(command);
  579. this.decoratedHandler.Handle(command);
  580. }
  581. private void Validate(TCommand command)
  582. {
  583. var validationContext =
  584. new ValidationContext(command, this.container, null);
  585. Validator.ValidateObject(command, validationContext);
  586. }
  587. }
  588. // Decorator that measures the time it takes to execute a command.
  589. public class MonitoringCommandHandlerDecorator<TCommand>
  590. : ICommandHandler<TCommand>
  591. {
  592. private readonly ICommandHandler<TCommand> decoratedHandler;
  593. private readonly ILogger logger;
  594. public MonitoringCommandHandlerDecorator(
  595. ICommandHandler<TCommand> decoratedHandler,
  596. ILogger logger)
  597. {
  598. this.decoratedHandler = decoratedHandler;
  599. this.logger = logger;
  600. }
  601. public void Handle(TCommand command)
  602. {
  603. var watch = Stopwatch.StartNew();
  604. this.decoratedHandler.Handle(command);
  605. this.logger.Log(string.Format("{0} executed in {1} ms.",
  606. command.GetType().Name, watch.ElapsedMilliseconds));
  607. }
  608. }
  609. [TestMethod]
  610. public static void TestRegisterOpenGenericDecorator()
  611. {
  612. // Arrange
  613. var container = new Container();
  614. container.RegisterSingle<ILogger, DebugLogger>();
  615. // Search the given assembly and register all concrete types that
  616. // implement ICommandHandler<TCommand>.
  617. container.RegisterManyForOpenGeneric(typeof(ICommandHandler<>),
  618. typeof(ICommandHandler<>).Assembly);
  619. // Wrap all ICommandHandler<TCommand> service types with a decorator
  620. // that measures and logs the duration of that handler.
  621. container.RegisterOpenGenericDecorator(typeof(ICommandHandler<>),
  622. typeof(MonitoringCommandHandlerDecorator<>));
  623. // Wrap all ICommandHandler<TCommand> types (in this case it will
  624. // wrap the monitoring decorator), but only if the TCommand contains
  625. // any properties.
  626. container.RegisterOpenGenericDecorator(typeof(ICommandHandler<>),
  627. typeof(ValidatorCommandHandlerDecorator<>), c =>
  628. {
  629. var commandType = c.ServiceType.GetGenericArguments()[0];
  630. bool mustDecorate = commandType.GetProperties().Any();
  631. return mustDecorate;
  632. });
  633. // Act
  634. var handler =
  635. container.GetInstance<ICommandHandler<CustomerMovedCommand>>();
  636. // Assert
  637. Assert.IsInstanceOfType(handler,
  638. typeof(ValidatorCommandHandlerDecorator<CustomerMovedCommand>));
  639. }
  640. ]]></code>
  641. </example>
  642. <param name="container">The container to make the registrations in.</param>
  643. <param name="openGenericServiceType">The definition of the open generic service type that will
  644. be wrapped by the given <paramref name="openGenericDecorator"/>.</param>
  645. <param name="openGenericDecorator">The definition of the open generic decorator type that will
  646. be used to wrap the original service type.</param>
  647. <exception cref="T:System.ArgumentNullException">Thrown when either <paramref name="container"/>,
  648. <paramref name="openGenericServiceType"/>, or <paramref name="openGenericDecorator"/> are null
  649. references.</exception>
  650. <exception cref="T:System.ArgumentException">Thrown when <paramref name="openGenericServiceType"/> is not
  651. an open generic type, when <paramref name="openGenericDecorator"/> does not inherit from or implement
  652. <paramref name="openGenericServiceType"/>, when <paramref name="openGenericDecorator"/> does not
  653. have a single public constructor, or when <paramref name="openGenericDecorator"/> does not
  654. contain a constructor that has exactly one argument of type
  655. <paramref name="openGenericServiceType"/>.</exception>
  656. </member>
  657. <member name="M:SimpleInjector.Extensions.GenericDecoratorExtensions.RegisterOpenGenericDecorator(SimpleInjector.Container,System.Type,System.Type,System.Predicate{SimpleInjector.Extensions.GenericDecoratorExtensions.PredicateContext})">
  658. <summary>
  659. Ensures that a closed generic version of the supplied <paramref name="openGenericDecorator"/>
  660. decorator is returned, wrapping the original closed generic version of the registered
  661. <paramref name="openGenericServiceType"/>, by injecting that service type into the constructor
  662. of the supplied <paramref name="openGenericDecorator"/>. Multiple decorators may be applied to the
  663. same <paramref name="openGenericServiceType"/>.
  664. </summary>
  665. <remarks>
  666. <para>
  667. The <b>RegisterOpenGenericDecorator</b> method works by hooking onto the container's
  668. <see cref="E:SimpleInjector.Container.ExpressionBuilt">ExpressionBuilt</see> event. This event fires after the
  669. <see cref="E:SimpleInjector.Container.ResolveUnregisteredType">ResolveUnregisteredType</see> event, which allows
  670. decoration of types that are resolved using unregistered type resolution. The
  671. <see cref="M:SimpleInjector.Extensions.OpenGenericRegistrationExtensions.RegisterOpenGeneric(SimpleInjector.Container,System.Type,System.Type)">RegisterOpenGeneric</see>
  672. extension method, for instance, hooks onto the <b>ResolveUnregisteredType</b>. This allows you to
  673. use <b>RegisterOpenGenericDecorator</b> on the same service type as <b>RegisterOpenGeneric</b>.
  674. </para>
  675. <para>
  676. Multiple decorators can be applied to the same service type. The order in which they are registered
  677. is the order they get applied in. This means that the decorator that gets registered first, gets
  678. applied first, which means that the next registered decorator, will wrap the first decorator, which
  679. wraps the original service type.
  680. </para>
  681. </remarks>
  682. <example>
  683. The following example shows the definition of a generic <b>ICommandHandler&lt;T&gt;</b> interface,
  684. a <b>CustomerMovedCommandHandler</b> implementing that interface, and a
  685. <b>ValidatorCommandHandlerDecorator&lt;T&gt;</b> that acts as a decorator for that interface.
  686. <code lang="cs"><![CDATA[
  687. using System.ComponentModel.DataAnnotations;
  688. using System.Diagnostics;
  689. using System.Linq;
  690. using Microsoft.VisualStudio.TestTools.UnitTesting;
  691. using SimpleInjector;
  692. using SimpleInjector.Extensions;
  693. public interface ICommandHandler<TCommand>
  694. {
  695. void Handle(TCommand command);
  696. }
  697. public class CustomerMovedCommand
  698. {
  699. [Required]
  700. public int CustomerId { get; set; }
  701. [Required]
  702. public Address Address { get; set; }
  703. }
  704. public class CustomerMovedCommandHandler
  705. : ICommandHandler<CustomerMovedCommand>
  706. {
  707. public void Handle(CustomerMovedCommand command)
  708. {
  709. // some logic
  710. }
  711. }
  712. // Decorator that validates commands before they get executed.
  713. public class ValidatorCommandHandlerDecorator<TCommand>
  714. : ICommandHandler<TCommand>
  715. {
  716. private readonly ICommandHandler<TCommand> decoratedHandler;
  717. private readonly Container container;
  718. public ValidatorCommandHandlerDecorator(
  719. ICommandHandler<TCommand> decoratedHandler,
  720. Container container)
  721. {
  722. this.decoratedHandler = decoratedHandler;
  723. this.container = container;
  724. }
  725. public void Handle(TCommand command)
  726. {
  727. this.Validate(command);
  728. this.decoratedHandler.Handle(command);
  729. }
  730. private void Validate(TCommand command)
  731. {
  732. var validationContext =
  733. new ValidationContext(command, this.container, null);
  734. Validator.ValidateObject(command, validationContext);
  735. }
  736. }
  737. // Decorator that measures the time it takes to execute a command.
  738. public class MonitoringCommandHandlerDecorator<TCommand>
  739. : ICommandHandler<TCommand>
  740. {
  741. private readonly ICommandHandler<TCommand> decoratedHandler;
  742. private readonly ILogger logger;
  743. public MonitoringCommandHandlerDecorator(
  744. ICommandHandler<TCommand> decoratedHandler,
  745. ILogger logger)
  746. {
  747. this.decoratedHandler = decoratedHandler;
  748. this.logger = logger;
  749. }
  750. public void Handle(TCommand command)
  751. {
  752. var watch = Stopwatch.StartNew();
  753. this.decoratedHandler.Handle(command);
  754. this.logger.Log(string.Format("{0} executed in {1} ms.",
  755. command.GetType().Name, watch.ElapsedMilliseconds));
  756. }
  757. }
  758. [TestMethod]
  759. public static void TestRegisterOpenGenericDecorator()
  760. {
  761. // Arrange
  762. var container = new Container();
  763. container.RegisterSingle<ILogger, DebugLogger>();
  764. // Search the given assembly and register all concrete types that
  765. // implement ICommandHandler<TCommand>.
  766. container.RegisterManyForOpenGeneric(typeof(ICommandHandler<>),
  767. typeof(ICommandHandler<>).Assembly);
  768. // Wrap all ICommandHandler<TCommand> service types with a decorator
  769. // that measures and logs the duration of that handler.
  770. container.RegisterOpenGenericDecorator(typeof(ICommandHandler<>),
  771. typeof(MonitoringCommandHandlerDecorator<>));
  772. // Wrap all ICommandHandler<TCommand> types (in this case it will
  773. // wrap the monitoring decorator), but only if the TCommand contains
  774. // any properties.
  775. container.RegisterOpenGenericDecorator(typeof(ICommandHandler<>),
  776. typeof(ValidatorCommandHandlerDecorator<>), c =>
  777. {
  778. var commandType = c.ServiceType.GetGenericArguments()[0];
  779. bool mustDecorate = commandType.GetProperties().Any();
  780. return mustDecorate;
  781. });
  782. // Act
  783. var handler =
  784. container.GetInstance<ICommandHandler<CustomerMovedCommand>>();
  785. // Assert
  786. Assert.IsInstanceOfType(handler,
  787. typeof(ValidatorCommandHandlerDecorator<CustomerMovedCommand>));
  788. }
  789. ]]></code>
  790. </example>
  791. <param name="container">The container to make the registrations in.</param>
  792. <param name="openGenericServiceType">The definition of the open generic service type that will
  793. be wrapped by the given <paramref name="openGenericDecorator"/>.</param>
  794. <param name="openGenericDecorator">The definition of the open generic decorator type that will
  795. be used to wrap the original service type.</param>
  796. <param name="predicate">The predicate that determines whether the
  797. <paramref name="openGenericDecorator"/> must be applied to a service type.</param>
  798. <exception cref="T:System.ArgumentNullException">Thrown when either <paramref name="container"/>,
  799. <paramref name="openGenericServiceType"/>, <paramref name="openGenericDecorator"/>, or
  800. <paramref name="predicate"/> are null references.</exception>
  801. <exception cref="T:System.ArgumentException">Thrown when <paramref name="openGenericServiceType"/> is not
  802. an open generic type, when <paramref name="openGenericDecorator"/> does not inherit from or
  803. implement <paramref name="openGenericServiceType"/>, when <paramref name="openGenericDecorator"/>
  804. does not have a single public constructor, or when <paramref name="openGenericDecorator"/> does
  805. not contain a constructor that has exactly one argument of type
  806. <paramref name="openGenericServiceType"/>.</exception>
  807. </member>
  808. <member name="T:SimpleInjector.Extensions.GenericDecoratorExtensions.PredicateContext">
  809. <summary>
  810. An instance of this type will be supplied to the <see cref="T:System.Predicate`1"/>
  811. delegate that is that is supplied to the
  812. <see cref="M:SimpleInjector.Extensions.GenericDecoratorExtensions.RegisterOpenGenericDecorator(SimpleInjector.Container,System.Type,System.Type,System.Predicate{SimpleInjector.Extensions.GenericDecoratorExtensions.PredicateContext})">RegisterOpenGenericDecorator</see>
  813. overload that takes this delegate. This type contains information about the decoration that is about
  814. to be applied and it allows users to examine the given instance to see whether the decorator should
  815. be applied or not.
  816. </summary>
  817. </member>
  818. <member name="P:SimpleInjector.Extensions.GenericDecoratorExtensions.PredicateContext.ServiceType">
  819. <summary>
  820. Gets the closed generic service type for which the decorator is about to be applied. The original
  821. service type will be returned, even if other decorators have already been applied to this type.
  822. </summary>
  823. <value>The closed generic service type.</value>
  824. </member>
  825. <member name="P:SimpleInjector.Extensions.GenericDecoratorExtensions.PredicateContext.ImplementationType">
  826. <summary>
  827. Gets the type of the implementation that is created by the container and for which the decorator
  828. is about to be applied. The original implementation type will be returned, even if other decorators
  829. have already been applied to this type. Please not that the implementation type can not always be
  830. determined. In that case the closed generic service type will be returned.
  831. </summary>
  832. <value>The implementation type.</value>
  833. </member>
  834. <member name="P:SimpleInjector.Extensions.GenericDecoratorExtensions.PredicateContext.AppliedDecorators">
  835. <summary>
  836. Gets the list of the types of decorators that have already been applied to this instance.
  837. </summary>
  838. <value>The applied decorators.</value>
  839. </member>
  840. <member name="P:SimpleInjector.Extensions.GenericDecoratorExtensions.PredicateContext.Expression">
  841. <summary>
  842. Gets the current <see cref="P:SimpleInjector.Extensions.GenericDecoratorExtensions.PredicateContext.Expression"/> object that describes the intention to create a new
  843. instance with its currently applied decorators.
  844. </summary>
  845. <value>The current expression that is about to be decorated.</value>
  846. </member>
  847. <member name="T:SimpleInjector.Extensions.GenericTypeBuilder">
  848. <summary>
  849. Helper class for building closed generic type for a given open generic type and a closed generic base.
  850. </summary>
  851. </member>
  852. <member name="T:SimpleInjector.Extensions.GenericTypeBuilder.BuildResult">
  853. <summary>Result of the GenericTypeBuilder.</summary>
  854. </member>
  855. <member name="T:SimpleInjector.Extensions.Helpers">
  856. <summary>
  857. Helper methods for the extensions.
  858. </summary>
  859. </member>
  860. <member name="T:SimpleInjector.Extensions.Requires">
  861. <summary>
  862. Internal helper class for precondition validation.
  863. </summary>
  864. </member>
  865. <member name="T:SimpleInjector.Extensions.BatchRegistrationCallback">
  866. <summary>
  867. Represents the method that will called to register one or multiple concrete. non-generic
  868. <paramref name="implementations"/> of the given closed generic type
  869. <paramref name="closedServiceType"/>.
  870. </summary>
  871. <param name="closedServiceType">The service type that needs to be registered.</param>
  872. <param name="implementations">One or more concrete types that implement the given
  873. <paramref name="closedServiceType"/>.</param>
  874. </member>
  875. <member name="T:SimpleInjector.Extensions.AccessibilityOption">
  876. <summary>Defines the accessibility of the types to search.</summary>
  877. </member>
  878. <member name="F:SimpleInjector.Extensions.AccessibilityOption.AllTypes">
  879. <summary>Load both public as internal types from the given assemblies.</summary>
  880. </member>
  881. <member name="F:SimpleInjector.Extensions.AccessibilityOption.PublicTypesOnly">
  882. <summary>Only load publicly exposed types from the given assemblies.</summary>
  883. </member>
  884. <member name="T:SimpleInjector.Extensions.OpenGenericBatchRegistrationExtensions">
  885. <summary>
  886. Provides a set of static (Shared in Visual Basic) methods for registration many concrete types at
  887. once that implement the same open generic service types in the <see cref="T:SimpleInjector.Container"/>.
  888. </summary>
  889. </member>
  890. <member name="M:SimpleInjector.Extensions.OpenGenericBatchRegistrationExtensions.RegisterManyForOpenGeneric(SimpleInjector.Container,System.Type,System.Reflection.Assembly[])">
  891. <summary>
  892. Registers all concrete, non-generic, publicly exposed types in the given set of
  893. <paramref name="assemblies"/> that implement the given <paramref name="openGenericServiceType"/>
  894. with a transient lifetime.
  895. </summary>
  896. <param name="container">The container to make the registrations in.</param>
  897. <param name="openGenericServiceType">The definition of the open generic type.</param>
  898. <param name="assemblies">A list of assemblies that will be searched.</param>
  899. <exception cref="T:System.ArgumentNullException">Thrown when <paramref name="container"/>,
  900. <paramref name="openGenericServiceType"/>, or <paramref name="assemblies"/> contain a null
  901. reference (Nothing in VB).</exception>
  902. <exception cref="T:System.ArgumentException">Thrown when <paramref name="openGenericServiceType"/> is not
  903. an open generic type.</exception>
  904. <exception cref="T:System.InvalidOperationException">Thrown when the given set of
  905. <paramref name="assemblies"/> contain multiple publicly exposed types that implement the same
  906. closed generic version of the given <paramref name="openGenericServiceType"/>.</exception>
  907. </member>
  908. <member name="M:SimpleInjector.Extensions.OpenGenericBatchRegistrationExtensions.RegisterManyForOpenGeneric(SimpleInjector.Container,System.Type,System.Collections.Generic.IEnumerable{System.Reflection.Assembly})">
  909. <summary>
  910. Registers all concrete, non-generic, publicly exposed types in the given
  911. <paramref name="assemblies"/> that implement the given <paramref name="openGenericServiceType"/>
  912. with a transient lifetime.
  913. </summary>
  914. <param name="container">The container to make the registrations in.</param>
  915. <param name="openGenericServiceType">The definition of the open generic type.</param>
  916. <param name="assemblies">A list of assemblies that will be searched.</param>
  917. <exception cref="T:System.ArgumentNullException">Thrown when <paramref name="container"/>,
  918. <paramref name="openGenericServiceType"/>, or <paramref name="assemblies"/> contain a null
  919. reference (Nothing in VB).</exception>
  920. <exception cref="T:System.ArgumentException">Thrown when <paramref name="openGenericServiceType"/> is not
  921. an open generic type.</exception>
  922. <exception cref="T:System.InvalidOperationException">Thrown when the given set of
  923. <paramref name="assemblies"/> contain multiple publicly exposed types that implement the same
  924. closed generic version of the given <paramref name="openGenericServiceType"/>.</exception>
  925. </member>
  926. <member name="M:SimpleInjector.Extensions.OpenGenericBatchRegistrationExtensions.RegisterManyForOpenGeneric(SimpleInjector.Container,System.Type,SimpleInjector.Extensions.AccessibilityOption,System.Reflection.Assembly[])">
  927. <summary>
  928. Registers all concrete, non-generic types with the given <paramref name="accessibility"/> in the
  929. given <paramref name="assemblies"/> that implement the given
  930. <paramref name="openGenericServiceType"/> with a transient lifetime.
  931. </summary>
  932. <param name="container">The container to make the registrations in.</param>
  933. <param name="openGenericServiceType">The definition of the open generic type.</param>
  934. <param name="accessibility">Defines which types should be used from the given assemblies.</param>
  935. <param name="assemblies">A list of assemblies that will be searched.</param>
  936. <exception cref="T:System.ArgumentNullException">Thrown when <paramref name="container"/>,
  937. <paramref name="openGenericServiceType"/>, or <paramref name="assemblies"/> contain a null
  938. reference (Nothing in VB).</exception>
  939. <exception cref="T:System.ArgumentException">Thrown when <paramref name="openGenericServiceType"/> is not
  940. an open generic type.</exception>
  941. <exception cref="T:System.InvalidOperationException">Thrown when the given set of
  942. <paramref name="assemblies"/> contain multiple types that implement the same closed generic
  943. version of the given <paramref name="openGenericServiceType"/>.</exception>
  944. <exception cref="T:System.ComponentModel.InvalidEnumArgumentException">Thrown when
  945. <paramref name="accessibility"/> contains an invalid value.</exception>
  946. </member>
  947. <member name="M:SimpleInjector.Extensions.OpenGenericBatchRegistrationExtensions.RegisterManyForOpenGeneric(SimpleInjector.Container,System.Type,SimpleInjector.Extensions.AccessibilityOption,System.Collections.Generic.IEnumerable{System.Reflection.Assembly})">
  948. <summary>
  949. Registers all concrete, non-generic types with the given <paramref name="accessibility"/> in the
  950. given <paramref name="assemblies"/> that implement the given
  951. <paramref name="openGenericServiceType"/> with a transient lifetime.
  952. </summary>
  953. <param name="container">The container to make the registrations in.</param>
  954. <param name="openGenericServiceType">The definition of the open generic type.</param>
  955. <param name="accessibility">Defines which types should be used from the given assemblies.</param>
  956. <param name="assemblies">A list of assemblies that will be searched.</param>
  957. <exception cref="T:System.ArgumentNullException">Thrown when <paramref name="container"/>,
  958. <paramref name="openGenericServiceType"/>, or <paramref name="assemblies"/> contain a null
  959. reference (Nothing in VB).</exception>
  960. <exception cref="T:System.ArgumentException">Thrown when <paramref name="openGenericServiceType"/> is not
  961. an open generic type.</exception>
  962. <exception cref="T:System.InvalidOperationException">Thrown when the given set of
  963. <paramref name="assemblies"/> contain multiple types that implement the same
  964. closed generic version of the given <paramref name="openGenericServiceType"/>.</exception>
  965. <exception cref="T:System.ComponentModel.InvalidEnumArgumentException">Thrown when
  966. <paramref name="accessibility"/> contains an invalid value.</exception>
  967. </member>
  968. <member name="M:SimpleInjector.Extensions.OpenGenericBatchRegistrationExtensions.RegisterManyForOpenGeneric(SimpleInjector.Container,System.Type,SimpleInjector.Extensions.BatchRegistrationCallback,System.Reflection.Assembly[])">
  969. <summary>
  970. Allows registration of all concrete, public, non-generic types in the given set of
  971. <paramref name="assemblies"/> that implement the given <paramref name="openGenericServiceType"/>,
  972. by supplying a <see cref="T:SimpleInjector.Extensions.BatchRegistrationCallback"/> delegate, that will be called for each
  973. found closed generic implementation of the given <paramref name="openGenericServiceType"/>.
  974. </summary>
  975. <param name="container">The container to make the registrations in.</param>
  976. <param name="openGenericServiceType">The definition of the open generic type.</param>
  977. <param name="callback">The delegate that will be called for each found closed generic version of
  978. the given open generic <paramref name="openGenericServiceType"/> to do the actual registration.</param>
  979. <param name="assemblies">A list of assemblies that will be searched.</param>
  980. <exception cref="T:System.ArgumentNullException">Thrown when <paramref name="container"/>,
  981. <paramref name="openGenericServiceType"/>, <paramref name="callback"/>, or
  982. <paramref name="assemblies"/> contain a null reference (Nothing in VB).</exception>
  983. <exception cref="T:System.ArgumentException">Thrown when <paramref name="openGenericServiceType"/> is not
  984. an open generic type.</exception>
  985. </member>
  986. <member name="M:SimpleInjector.Extensions.OpenGenericBatchRegistrationExtensions.RegisterManyForOpenGeneric(SimpleInjector.Container,System.Type,SimpleInjector.Extensions.BatchRegistrationCallback,System.Collections.Generic.IEnumerable{System.Reflection.Assembly})">
  987. <summary>
  988. Allows registration of all concrete, public, non-generic types in the given set of
  989. <paramref name="assemblies"/> that implement the given <paramref name="openGenericServiceType"/>,
  990. by supplying a <see cref="T:SimpleInjector.Extensions.BatchRegistrationCallback"/> delegate, that will be called for each
  991. found closed generic implementation of the given <paramref name="openGenericServiceType"/>.
  992. </summary>
  993. <param name="container">The container to make the registrations in.</param>
  994. <param name="openGenericServiceType">The definition of the open generic type.</param>
  995. <param name="callback">The delegate that will be called for each found closed generic version of
  996. the given open generic <paramref name="openGenericServiceType"/> to do the actual registration.</param>
  997. <param name="assemblies">A list of assemblies that will be searched.</param>
  998. <exception cref="T:System.ArgumentNullException">Thrown when <paramref name="container"/>,
  999. <paramref name="openGenericServiceType"/>, <paramref name="callback"/>, or
  1000. <paramref name="assemblies"/> contain a null reference (Nothing in VB).</exception>
  1001. <exception cref="T:System.ArgumentException">Thrown when <paramref name="openGenericServiceType"/> is not
  1002. an open generic type.</exception>
  1003. </member>
  1004. <member name="M:SimpleInjector.Extensions.OpenGenericBatchRegistrationExtensions.RegisterManyForOpenGeneric(SimpleInjector.Container,System.Type,SimpleInjector.Extensions.AccessibilityOption,SimpleInjector.Extensions.BatchRegistrationCallback,System.Reflection.Assembly[])">
  1005. <summary>
  1006. Allows registration of all concrete, non-generic types with the given
  1007. <paramref name="accessibility"/> in the given set of <paramref name="assemblies"/> that implement
  1008. the given <paramref name="openGenericServiceType"/>, by supplying a
  1009. <see cref="T:SimpleInjector.Extensions.BatchRegistrationCallback"/> delegate, that will be called for each found closed generic
  1010. implementation of the given <paramref name="openGenericServiceType"/>.
  1011. </summary>
  1012. <param name="container">The container to make the registrations in.</param>
  1013. <param name="openGenericServiceType">The definition of the open generic type.</param>
  1014. <param name="accessibility">Defines which types should be used from the given assemblies.</param>
  1015. <param name="callback">The delegate that will be called for each found closed generic version of
  1016. the given open generic <paramref name="openGenericServiceType"/> to do the actual registration.</param>
  1017. <param name="assemblies">A list of assemblies that will be searched.</param>
  1018. <exception cref="T:System.ArgumentNullException">Thrown when <paramref name="container"/>,
  1019. <paramref name="openGenericServiceType"/>, <paramref name="callback"/>, or
  1020. <paramref name="assemblies"/> contain a null reference (Nothing in VB).</exception>
  1021. <exception cref="T:System.ArgumentException">Thrown when <paramref name="openGenericServiceType"/> is not
  1022. an open generic type.</exception>
  1023. <exception cref="T:System.ComponentModel.InvalidEnumArgumentException">Thrown when
  1024. <paramref name="accessibility"/> contains an invalid value.</exception>
  1025. </member>
  1026. <member name="M:SimpleInjector.Extensions.OpenGenericBatchRegistrationExtensions.RegisterManyForOpenGeneric(SimpleInjector.Container,System.Type,SimpleInjector.Extensions.AccessibilityOption,SimpleInjector.Extensions.BatchRegistrationCallback,System.Collections.Generic.IEnumerable{System.Reflection.Assembly})">
  1027. <summary>
  1028. Allows registration of all concrete, non-generic types with the given
  1029. <paramref name="accessibility"/> in the given set of <paramref name="assemblies"/> that implement
  1030. the given <paramref name="openGenericServiceType"/>, by supplying a
  1031. <see cref="T:SimpleInjector.Extensions.BatchRegistrationCallback"/> delegate, that will be called for each found closed generic
  1032. implementation of the given <paramref name="openGenericServiceType"/>.
  1033. </summary>
  1034. <param name="container">The container to make the registrations in.</param>
  1035. <param name="openGenericServiceType">The definition of the open generic type.</param>
  1036. <param name="accessibility">Defines which types should be used from the given assemblies.</param>
  1037. <param name="callback">The delegate that will be called for each found closed generic version of
  1038. the given open generic <paramref name="openGenericServiceType"/> to do the actual registration.</param>
  1039. <param name="assemblies">A list of assemblies that will be searched.</param>
  1040. <exception cref="T:System.ArgumentNullException">Thrown when <paramref name="container"/>,
  1041. <paramref name="openGenericServiceType"/>, <paramref name="callback"/>, or
  1042. <paramref name="assemblies"/> contain a null reference (Nothing in VB).</exception>
  1043. <exception cref="T:System.ArgumentException">Thrown when <paramref name="openGenericServiceType"/> is not
  1044. an open generic type.</exception>
  1045. <exception cref="T:System.ComponentModel.InvalidEnumArgumentException">Thrown when
  1046. <paramref name="accessibility"/> contains an invalid value.</exception>
  1047. </member>
  1048. <member name="M:SimpleInjector.Extensions.OpenGenericBatchRegistrationExtensions.RegisterManySinglesForOpenGeneric(SimpleInjector.Container,System.Type,System.Reflection.Assembly[])">
  1049. <summary>
  1050. Registers all concrete, non-generic, publicly exposed types in the given
  1051. <paramref name="assemblies"/> that implement the given
  1052. <paramref name="openGenericServiceType"/> with a singleton lifetime.
  1053. </summary>
  1054. <param name="container">The container to make the registrations in.</param>
  1055. <param name="openGenericServiceType">The definition of the open generic type.</param>
  1056. <param name="assemblies">A list of assemblies that will be searched.</param>
  1057. <exception cref="T:System.ArgumentNullException">Thrown when <paramref name="container"/>,
  1058. <paramref name="openGenericServiceType"/>, or <paramref name="assemblies"/> contain a null
  1059. reference (Nothing in VB).</exception>
  1060. <exception cref="T:System.ArgumentException">Thrown when <paramref name="openGenericServiceType"/> is not
  1061. an open generic type.</exception>
  1062. <exception cref="T:System.InvalidOperationException">Thrown when the given set of
  1063. <paramref name="assemblies"/> contain multiple publicly exposed types that implement the same
  1064. closed generic version of the given <paramref name="openGenericServiceType"/>.</exception>
  1065. </member>
  1066. <member name="M:SimpleInjector.Extensions.OpenGenericBatchRegistrationExtensions.RegisterManySinglesForOpenGeneric(SimpleInjector.Container,System.Type,System.Collections.Generic.IEnumerable{System.Reflection.Assembly})">
  1067. <summary>
  1068. Registers all concrete, non-generic, publicly exposed types in the given
  1069. <paramref name="assemblies"/> that implement the given <paramref name="openGenericServiceType"/>
  1070. with a singleton lifetime.
  1071. </summary>
  1072. <param name="container">The container to make the registrations in.</param>
  1073. <param name="openGenericServiceType">The definition of the open generic type.</param>
  1074. <param name="assemblies">A list of assemblies that will be searched.</param>
  1075. <exception cref="T:System.ArgumentNullException">Thrown when <paramref name="container"/>,
  1076. <paramref name="openGenericServiceType"/>, or <paramref name="assemblies"/> contain a null
  1077. reference (Nothing in VB).</exception>
  1078. <exception cref="T:System.ArgumentException">Thrown when <paramref name="openGenericServiceType"/> is not
  1079. an open generic type.</exception>
  1080. <exception cref="T:System.InvalidOperationException">Thrown when the given set of
  1081. <paramref name="assemblies"/> contain multiple publicly exposed types that implement the same
  1082. closed generic version of the given <paramref name="openGenericServiceType"/>.</exception>
  1083. </member>
  1084. <member name="M:SimpleInjector.Extensions.OpenGenericBatchRegistrationExtensions.RegisterManySinglesForOpenGeneric(SimpleInjector.Container,System.Type,SimpleInjector.Extensions.AccessibilityOption,System.Reflection.Assembly[])">
  1085. <summary>
  1086. Registers all concrete, non-generic types with the given <paramref name="accessibility"/> in the
  1087. given <paramref name="assemblies"/> that implement the given
  1088. <paramref name="openGenericServiceType"/> with a singleton lifetime.
  1089. </summary>
  1090. <param name="container">The container to make the registrations in.</param>
  1091. <param name="openGenericServiceType">The definition of the open generic type.</param>
  1092. <param name="accessibility">Defines which types should be used from the given assemblies.</param>
  1093. <param name="assemblies">A list of assemblies that will be searched.</param>
  1094. <exception cref="T:System.ArgumentNullException">Thrown when <paramref name="container"/>,
  1095. <paramref name="openGenericServiceType"/>, or <paramref name="assemblies"/> contain a null
  1096. reference (Nothing in VB).</exception>
  1097. <exception cref="T:System.ArgumentException">Thrown when <paramref name="openGenericServiceType"/> is not
  1098. an open generic type.</exception>
  1099. <exception cref="T:System.InvalidOperationException">Thrown when the given set of
  1100. <paramref name="assemblies"/> contain multiple types that implement the same closed generic
  1101. version of the given <paramref name="openGenericServiceType"/>.</exception>
  1102. <exception cref="T:System.ComponentModel.InvalidEnumArgumentException">Thrown when
  1103. <paramref name="accessibility"/> contains an invalid value.</exception>
  1104. </member>
  1105. <member name="M:SimpleInjector.Extensions.OpenGenericBatchRegistrationExtensions.RegisterManySinglesForOpenGeneric(SimpleInjector.Container,System.Type,SimpleInjector.Extensions.AccessibilityOption,System.Collections.Generic.IEnumerable{System.Reflection.Assembly})">
  1106. <summary>
  1107. Registers all concrete, non-generic types with the given <paramref name="accessibility"/> in the
  1108. given <paramref name="assemblies"/> that implement the given
  1109. <paramref name="openGenericServiceType"/> with a singleton lifetime.
  1110. </summary>
  1111. <param name="container">The container to make the registrations in.</param>
  1112. <param name="openGenericServiceType">The definition of the open generic type.</param>
  1113. <param name="accessibility">Defines which types should be used from the given assemblies.</param>
  1114. <param name="assemblies">A list of assemblies that will be searched.</param>
  1115. <exception cref="T:System.ArgumentNullException">Thrown when <paramref name="container"/>,
  1116. <paramref name="openGenericServiceType"/>, or <paramref name="assemblies"/> contain a null
  1117. reference (Nothing in VB).</exception>
  1118. <exception cref="T:System.ArgumentException">Thrown when <paramref name="openGenericServiceType"/> is not
  1119. an open generic type.</exception>
  1120. <exception cref="T:System.InvalidOperationException">Thrown when the given set of
  1121. <paramref name="assemblies"/> contain multiple types that implement the same
  1122. closed generic version of the given <paramref name="openGenericServiceType"/>.</exception>
  1123. <exception cref="T:System.ComponentModel.InvalidEnumArgumentException">Thrown when
  1124. <paramref name="accessibility"/> contains an invalid value.</exception>
  1125. </member>
  1126. <member name="M:SimpleInjector.Extensions.OpenGenericBatchRegistrationExtensions.RegisterManyForOpenGeneric(SimpleInjector.Container,System.Type,System.Type[])">
  1127. <summary>
  1128. Registers all supplied <paramref name="typesToRegister"/> by a closed generic definition of the
  1129. given <paramref name="openGenericServiceType"/> with a transient lifetime.
  1130. </summary>
  1131. <param name="container">The container to make the registrations in.</param>
  1132. <param name="openGenericServiceType">The definition of the open generic type.</param>
  1133. <param name="typesToRegister">The list of types that must be registered according to the given
  1134. <paramref name="openGenericServiceType"/> definition.</param>
  1135. <exception cref="T:System.ArgumentNullException">Thrown when <paramref name="container"/>,
  1136. <paramref name="openGenericServiceType"/>, or <paramref name="typesToRegister"/> contain a null
  1137. reference (Nothing in VB).</exception>
  1138. <exception cref="T:System.ArgumentException">Thrown when <paramref name="typesToRegister"/> contains a null
  1139. (Nothing in VB) element, when the <paramref name="openGenericServiceType"/> is not an open generic
  1140. type, or one of the types supplied in <paramref name="typesToRegister"/> does not implement a
  1141. closed version of <paramref name="openGenericServiceType"/>.
  1142. </exception>
  1143. <exception cref="T:System.InvalidOperationException">Thrown when there are multiple types in the given
  1144. <paramref name="typesToRegister"/> collection that implement the same closed version of the
  1145. supplied <paramref name="openGenericServiceType"/>.
  1146. </exception>
  1147. </member>
  1148. <member name="M:SimpleInjector.Extensions.OpenGenericBatchRegistrationExtensions.RegisterManyForOpenGeneric(SimpleInjector.Container,System.Type,System.Collections.Generic.IEnumerable{System.Type})">
  1149. <summary>
  1150. Registers all supplied <paramref name="typesToRegister"/> by a closed generic definition of the
  1151. given <paramref name="openGenericServiceType"/> with a transient lifetime.
  1152. </summary>
  1153. <param name="container">The container to make the registrations in.</param>
  1154. <param name="openGenericServiceType">The definition of the open generic type.</param>
  1155. <param name="typesToRegister">The list of types that must be registered according to the given
  1156. <paramref name="openGenericServiceType"/> definition.</param>
  1157. <exception cref="T:System.ArgumentNullException">Thrown when <paramref name="container"/>,
  1158. <paramref name="openGenericServiceType"/>, or <paramref name="typesToRegister"/> contain a null
  1159. reference (Nothing in VB).</exception>
  1160. <exception cref="T:System.ArgumentException">Thrown when <paramref name="typesToRegister"/> contains a null
  1161. (Nothing in VB) element, when the <paramref name="openGenericServiceType"/> is not an open generic
  1162. type, or one of the types supplied in <paramref name="typesToRegister"/> does not implement a
  1163. closed version of <paramref name="openGenericServiceType"/>.
  1164. </exception>
  1165. <exception cref="T:System.InvalidOperationException">Thrown when there are multiple types in the given
  1166. <paramref name="typesToRegister"/> collection that implement the same closed version of the
  1167. supplied <paramref name="openGenericServiceType"/>.
  1168. </exception>
  1169. </member>
  1170. <member name="M:SimpleInjector.Extensions.OpenGenericBatchRegistrationExtensions.RegisterManyForOpenGeneric(SimpleInjector.Container,System.Type,SimpleInjector.Extensions.BatchRegistrationCallback,System.Collections.Generic.IEnumerable{System.Type})">
  1171. <summary>
  1172. Allows registration of all supplied <paramref name="typesToRegister"/> by a closed generic
  1173. definition of the given <paramref name="openGenericServiceType"/>, by supplying a
  1174. <see cref="T:SimpleInjector.Extensions.BatchRegistrationCallback"/> delegate, that will be called for each found closed generic
  1175. implementation.
  1176. </summary>
  1177. <param name="container">The container to make the registrations in.</param>
  1178. <param name="openGenericServiceType">The definition of the open generic type.</param>
  1179. <param name="callback">The delegate that will be called for each found closed generic version of
  1180. the given open generic <paramref name="openGenericServiceType"/> to do the actual registration.</param>
  1181. <param name="typesToRegister">The list of types that must be registered according to the given
  1182. <paramref name="openGenericServiceType"/> definition.</param>
  1183. <exception cref="T:System.ArgumentNullException">Thrown when <paramref name="container"/>,
  1184. <paramref name="openGenericServiceType"/>, <paramref name="callback"/>, or
  1185. <paramref name="typesToRegister"/> contain a null reference (Nothing in VB).</exception>
  1186. <exception cref="T:System.ArgumentException">Thrown when <paramref name="typesToRegister"/> contains a null
  1187. (Nothing in VB) element, when the <paramref name="openGenericServiceType"/> is not an open generic
  1188. type, or one of the types supplied in <paramref name="typesToRegister"/> does not implement a
  1189. closed version of <paramref name="openGenericServiceType"/>.
  1190. </exception>
  1191. </member>
  1192. <member name="M:SimpleInjector.Extensions.OpenGenericBatchRegistrationExtensions.RegisterManySinglesForOpenGeneric(SimpleInjector.Container,System.Type,System.Type[])">
  1193. <summary>
  1194. Registers all supplied <paramref name="typesToRegister"/> by a closed generic definition of the
  1195. given <paramref name="openGenericServiceType"/> with a singleton lifetime.
  1196. </summary>
  1197. <param name="container">The container to make the registrations in.</param>
  1198. <param name="openGenericServiceType">The definition of the open generic type.</param>
  1199. <param name="typesToRegister">The list of types that must be registered according to the given
  1200. <paramref name="openGenericServiceType"/> definition.</param>
  1201. <exception cref="T:System.ArgumentNullException">Thrown when <paramref name="container"/>,
  1202. <paramref name="openGenericServiceType"/>, or <paramref name="typesToRegister"/> contain a null
  1203. reference (Nothing in VB).</exception>
  1204. <exception cref="T:System.ArgumentException">Thrown when <paramref name="typesToRegister"/> contains a null
  1205. (Nothing in VB) element, when the <paramref name="openGenericServiceType"/> is not an open generic
  1206. type, or one of the types supplied in <paramref name="typesToRegister"/> does not implement a
  1207. closed version of <paramref name="openGenericServiceType"/>.
  1208. </exception>
  1209. <exception cref="T:System.InvalidOperationException">Thrown when there are multiple types in the given
  1210. <paramref name="typesToRegister"/> collection that implement the same closed version of the
  1211. supplied <paramref name="openGenericServiceType"/>.
  1212. </exception>
  1213. </member>
  1214. <member name="M:SimpleInjector.Extensions.OpenGenericBatchRegistrationExtensions.RegisterManySinglesForOpenGeneric(SimpleInjector.Container,System.Type,System.Collections.Generic.IEnumerable{System.Type})">
  1215. <summary>
  1216. Registers all supplied <paramref name="typesToRegister"/> by a closed generic definition of the
  1217. given <paramref name="openGenericServiceType"/> with a singleton lifetime.
  1218. </summary>
  1219. <param name="container">The container to make the registrations in.</param>
  1220. <param name="openGenericServiceType">The definition of the open generic type.</param>
  1221. <param name="typesToRegister">The list of types that must be registered according to the given
  1222. <paramref name="openGenericServiceType"/> definition.</param>
  1223. <exception cref="T:System.ArgumentNullException">Thrown when <paramref name="container"/>,
  1224. <paramref name="openGenericServiceType"/>, or <paramref name="typesToRegister"/> contain a null
  1225. reference (Nothing in VB).</exception>
  1226. <exception cref="T:System.ArgumentException">Thrown when <paramref name="typesToRegister"/> contains a null
  1227. (Nothing in VB) element, when the <paramref name="openGenericServiceType"/> is not an open generic
  1228. type, or one of the types supplied in <paramref name="typesToRegister"/> does not implement a
  1229. closed version of <paramref name="openGenericServiceType"/>.
  1230. </exception>
  1231. <exception cref="T:System.InvalidOperationException">Thrown when there are multiple types in the given
  1232. <paramref name="typesToRegister"/> collection that implement the same closed version of the
  1233. supplied <paramref name="openGenericServiceType"/>.
  1234. </exception>
  1235. </member>
  1236. <member name="M:SimpleInjector.Extensions.OpenGenericBatchRegistrationExtensions.GetTypesToRegister(System.Type,System.Reflection.Assembly[])">
  1237. <summary>
  1238. Returns all public types from the supplied <paramref name="assemblies"/> that implement or inherit
  1239. from the supplied <paramref name="openGenericServiceType"/>.
  1240. </summary>
  1241. <remarks>
  1242. Use this method when you need influence the types that are registered using
  1243. <see cref="M:SimpleInjector.Extensions.OpenGenericBatchRegistrationExtensions.RegisterManyForOpenGeneric(SimpleInjector.Container,System.Type,System.Reflection.Assembly[])">RegisterManyForOpenGeneric</see>.
  1244. The <b>RegisterManyForOpenGeneric</b> overloads that take a collection of <see cref="T:System.Reflection.Assembly"/>
  1245. objects use this method to get the list of types that need to be registered. Instead of calling
  1246. such overload, you can call an overload that takes a list of <see cref="T:System.Type"/> objects and pass
  1247. in a filtered result from this <b>GetTypesToRegister</b> method.
  1248. <code lang="cs"><![CDATA[
  1249. var container = new Container();
  1250. var types = OpenGenericBatchRegistrationExtensions
  1251. .GetTypesToRegister(typeof(ICommandHandler<>), typeof(ICommandHandler<>).Assembly)
  1252. .Where(type => !type.Name.EndsWith("Decorator"));
  1253. container.RegisterManyForOpenGeneric(typeof(ICommandHandler<>), types);
  1254. ]]></code>
  1255. This example calls the <b>GetTypesToRegister</b> method to request a list of concrete implementations
  1256. of the <b>ICommandHandler&lt;T&gt;</b> interface from the assembly of that interface. After that
  1257. all types which name ends with 'Decorator' are filtered out. This list is supplied to an
  1258. <see cref="M:SimpleInjector.Extensions.OpenGenericBatchRegistrationExtensions.RegisterManyForOpenGeneric(SimpleInjector.Container,System.Type,System.Reflection.Assembly[])">RegisterManyForOpenGeneric</see>
  1259. overload that takes a list of types to finish the
  1260. registration.
  1261. </remarks>
  1262. <param name="openGenericServiceType">The definition of the open generic type.</param>
  1263. <param name="assemblies">A list of assemblies that will be searched.</param>
  1264. <returns>A list of types.</returns>
  1265. <exception cref="T:System.ArgumentNullException">Thrown when <paramref name="openGenericServiceType"/>, or
  1266. <paramref name="assemblies"/> contain a null reference (Nothing in VB).</exception>
  1267. </member>
  1268. <member name="M:SimpleInjector.Extensions.OpenGenericBatchRegistrationExtensions.GetTypesToRegister(System.Type,System.Collections.Generic.IEnumerable{System.Reflection.Assembly})">
  1269. <summary>
  1270. Returns all public types from the supplied <paramref name="assemblies"/> that implement or inherit
  1271. from the supplied <paramref name="openGenericServiceType"/>.
  1272. </summary>
  1273. <remarks>
  1274. Use this method when you need influence the types that are registered using
  1275. <see cref="M:SimpleInjector.Extensions.OpenGenericBatchRegistrationExtensions.RegisterManyForOpenGeneric(SimpleInjector.Container,System.Type,System.Reflection.Assembly[])">RegisterManyForOpenGeneric</see>.
  1276. The <b>RegisterManyForOpenGeneric</b> overloads that take a collection of <see cref="T:System.Reflection.Assembly"/>
  1277. objects use this method to get the list of types that need to be registered. Instead of calling
  1278. such overload, you can call an overload that takes a list of <see cref="T:System.Type"/> objects and pass
  1279. in a filtered result from this <b>GetTypesToRegister</b> method.
  1280. <code lang="cs"><![CDATA[
  1281. var container = new Container();
  1282. var types = OpenGenericBatchRegistrationExtensions
  1283. .GetTypesToRegister(typeof(ICommandHandler<>), typeof(ICommandHandler<>).Assembly)
  1284. .Where(type => !type.Name.EndsWith("Decorator"));
  1285. container.RegisterManyForOpenGeneric(typeof(ICommandHandler<>), types);
  1286. ]]></code>
  1287. This example calls the <b>GetTypesToRegister</b> method to request a list of concrete implementations
  1288. of the <b>ICommandHandler&lt;T&gt;</b> interface from the assembly of that interface. After that
  1289. all types which name ends with 'Decorator' are filtered out. This list is supplied to an
  1290. <see cref="M:SimpleInjector.Extensions.OpenGenericBatchRegistrationExtensions.RegisterManyForOpenGeneric(SimpleInjector.Container,System.Type,System.Reflection.Assembly[])">RegisterManyForOpenGeneric</see>
  1291. overload that takes a list of types to finish the registration.
  1292. </remarks>
  1293. <param name="openGenericServiceType">The definition of the open generic type.</param>
  1294. <param name="assemblies">A list of assemblies that will be searched.</param>
  1295. <returns>A list of types.</returns>
  1296. <exception cref="T:System.ArgumentNullException">Thrown when <paramref name="openGenericServiceType"/>, or
  1297. <paramref name="assemblies"/> contain a null reference (Nothing in VB).</exception>
  1298. </member>
  1299. <member name="M:SimpleInjector.Extensions.OpenGenericBatchRegistrationExtensions.GetTypesToRegister(System.Type,SimpleInjector.Extensions.AccessibilityOption,System.Reflection.Assembly[])">
  1300. <summary>
  1301. Returns all types from the supplied <paramref name="assemblies"/> that implement or inherit
  1302. from the supplied <paramref name="openGenericServiceType"/>.
  1303. </summary>
  1304. <remarks>
  1305. Use this method when you need influence the types that are registered using
  1306. <see cref="M:SimpleInjector.Extensions.OpenGenericBatchRegistrationExtensions.RegisterManyForOpenGeneric(SimpleInjector.Container,System.Type,System.Reflection.Assembly[])">RegisterManyForOpenGeneric</see>.
  1307. The <b>RegisterManyForOpenGeneric</b> overloads that take a collection of <see cref="T:System.Reflection.Assembly"/>
  1308. objects use this method to get the list of types that need to be registered. Instead of calling
  1309. such overload, you can call an overload that takes a list of <see cref="T:System.Type"/> objects and pass
  1310. in a filtered result from this <b>GetTypesToRegister</b> method.
  1311. <code lang="cs"><![CDATA[
  1312. var container = new Container();
  1313. var types = OpenGenericBatchRegistrationExtensions
  1314. .GetTypesToRegister(typeof(ICommandHandler<>), AccessibilityOption.PublicTypesOnly,
  1315. typeof(ICommandHandler<>).Assembly)
  1316. .Where(type => !type.Name.EndsWith("Decorator"));
  1317. container.RegisterManyForOpenGeneric(typeof(ICommandHandler<>), types);
  1318. ]]></code>
  1319. This example calls the <b>GetTypesToRegister</b> method to request a list of concrete implementations
  1320. of the <b>ICommandHandler&lt;T&gt;</b> interface from the assembly of that interface. After that
  1321. all types which name ends with 'Decorator' are filtered out. This list is supplied to an
  1322. <see cref="M:SimpleInjector.Extensions.OpenGenericBatchRegistrationExtensions.RegisterManyForOpenGeneric(SimpleInjector.Container,System.Type,System.Reflection.Assembly[])">RegisterManyForOpenGeneric</see>
  1323. overload that takes a list of types to finish the
  1324. registration.
  1325. </remarks>
  1326. <param name="openGenericServiceType">The definition of the open generic type.</param>
  1327. <param name="accessibility">Defines which types should be used from the given assemblies.</param>
  1328. <param name="assemblies">A list of assemblies that will be searched.</param>
  1329. <returns>A list of types.</returns>
  1330. <exception cref="T:System.ComponentModel.InvalidEnumArgumentException">Thrown when
  1331. <paramref name="accessibility"/> contains an invalid value.</exception>
  1332. <exception cref="T:System.ArgumentNullException">Thrown when <paramref name="openGenericServiceType"/>, or
  1333. <paramref name="assemblies"/> contain a null reference (Nothing in VB).</exception>
  1334. </member>
  1335. <member name="M:SimpleInjector.Extensions.OpenGenericBatchRegistrationExtensions.GetTypesToRegister(System.Type,SimpleInjector.Extensions.AccessibilityOption,System.Collections.Generic.IEnumerable{System.Reflection.Assembly})">
  1336. <summary>
  1337. Returns all types from the supplied <paramref name="assemblies"/> that implement or inherit
  1338. from the supplied <paramref name="openGenericServiceType"/>.
  1339. </summary>
  1340. <remarks>
  1341. Use this method when you need influence the types that are registered using
  1342. <see cref="M:SimpleInjector.Extensions.OpenGenericBatchRegistrationExtensions.RegisterManyForOpenGeneric(SimpleInjector.Container,System.Type,System.Reflection.Assembly[])">RegisterManyForOpenGeneric</see>.
  1343. The <b>RegisterManyForOpenGeneric</b> overloads that take a collection of <see cref="T:System.Reflection.Assembly"/>
  1344. objects use this method to get the list of types that need to be registered. Instead of calling
  1345. such overload, you can call an overload that takes a list of <see cref="T:System.Type"/> objects and pass
  1346. in a filtered result from this <b>GetTypesToRegister</b> method.
  1347. <code lang="cs"><![CDATA[
  1348. var container = new Container();
  1349. var types = OpenGenericBatchRegistrationExtensions
  1350. .GetTypesToRegister(typeof(ICommandHandler<>), AccessibilityOption.PublicTypesOnly,
  1351. typeof(ICommandHandler<>).Assembly)
  1352. .Where(type => !type.Name.EndsWith("Decorator"));
  1353. container.RegisterManyForOpenGeneric(typeof(ICommandHandler<>), types);
  1354. ]]></code>
  1355. This example calls the <b>GetTypesToRegister</b> method to request a list of concrete implementations
  1356. of the <b>ICommandHandler&lt;T&gt;</b> interface from the assembly of that interface. After that
  1357. all types which name ends with 'Decorator' are filtered out. This list is supplied to an
  1358. <see cref="M:SimpleInjector.Extensions.OpenGenericBatchRegistrationExtensions.RegisterManyForOpenGeneric(SimpleInjector.Container,System.Type,System.Reflection.Assembly[])">RegisterManyForOpenGeneric</see>
  1359. overload that takes a list of types to finish the registration.
  1360. </remarks>
  1361. <param name="openGenericServiceType">The definition of the open generic type.</param>
  1362. <param name="accessibility">Defines which types should be used from the given assemblies.</param>
  1363. <param name="assemblies">A list of assemblies that will be searched.</param>
  1364. <returns>A list of types.</returns>
  1365. <exception cref="T:System.ComponentModel.InvalidEnumArgumentException">Thrown when
  1366. <paramref name="accessibility"/> contains an invalid value.</exception>
  1367. <exception cref="T:System.ArgumentNullException">Thrown when <paramref name="openGenericServiceType"/>, or
  1368. <paramref name="assemblies"/> contain a null reference (Nothing in VB).</exception>
  1369. </member>
  1370. <member name="T:SimpleInjector.Extensions.NonGenericRegistrationsExtensions">
  1371. <summary>
  1372. Extension methods with non-generic method overloads.
  1373. </summary>
  1374. </member>
  1375. <member name="M:SimpleInjector.Extensions.NonGenericRegistrationsExtensions.RegisterSingle(SimpleInjector.Container,System.Type,System.Type)">
  1376. <summary>
  1377. Registers that the same instance of type <paramref name="implementation"/> will be returned every
  1378. time a <paramref name="serviceType"/> type is requested. If <paramref name="serviceType"/> and
  1379. <paramref name="implementation"/> represent the same type, the type is registered by itself.
  1380. </summary>
  1381. <param name="container">The container to make the registrations in.</param>
  1382. <param name="serviceType">The base type or interface to register.</param>
  1383. <param name="implementation">The actual type that will be returned when requested.</param>
  1384. <exception cref="T:System.ArgumentNullException">Thrown when either <paramref name="container"/>,
  1385. <paramref name="serviceType"/> or <paramref name="implementation"/> are null references (Nothing in
  1386. VB).</exception>
  1387. <exception cref="T:System.ArgumentException">Thrown when <paramref name="implementation"/> is
  1388. no sub type from <paramref name="serviceType"/>, or when one of them represents an open generic
  1389. type.</exception>
  1390. </member>
  1391. <member name="M:SimpleInjector.Extensions.NonGenericRegistrationsExtensions.RegisterSingle(SimpleInjector.Container,System.Type,System.Func{System.Object})">
  1392. <summary>
  1393. Registers the specified delegate that allows constructing a single <paramref name="serviceType"/>
  1394. instance. The container will call this delegate at most once during the lifetime of the application.
  1395. </summary>
  1396. <param name="container">The container to make the registrations in.</param>
  1397. <param name="serviceType">The base type or interface to register.</param>
  1398. <param name="instanceCreator">The delegate that will be used for creating that single instance.</param>
  1399. <exception cref="T:System.ArgumentException">Thrown when <paramref name="serviceType"/> represents an open
  1400. generic type.</exception>
  1401. <exception cref="T:System.ArgumentNullException">Thrown when either <paramref name="container"/>,
  1402. <paramref name="serviceType"/> or <paramref name="instanceCreator"/> are null references (Nothing in
  1403. VB).</exception>
  1404. </member>
  1405. <member name="M:SimpleInjector.Extensions.NonGenericRegistrationsExtensions.RegisterSingle(SimpleInjector.Container,System.Type,System.Object)">
  1406. <summary>
  1407. Registers a single instance. This <paramref name="instance"/> must be thread-safe.
  1408. </summary>
  1409. <param name="container">The container to make the registrations in.</param>
  1410. <param name="serviceType">The base type or interface to register.</param>
  1411. <param name="instance">The instance to register.</param>
  1412. <exception cref="T:System.ArgumentNullException">Thrown when either <paramref name="container"/>,
  1413. <paramref name="serviceType"/> or <paramref name="instance"/> are null references (Nothing in
  1414. VB).</exception>
  1415. <exception cref="T:System.ArgumentException">Thrown when <paramref name="instance"/> is
  1416. no sub type from <paramref name="serviceType"/>.</exception>
  1417. </member>
  1418. <member name="M:SimpleInjector.Extensions.NonGenericRegistrationsExtensions.Register(SimpleInjector.Container,System.Type)">
  1419. <summary>
  1420. Registers that a new instance of <paramref name="concreteType"/> will be returned every time it
  1421. is requested (transient).
  1422. </summary>
  1423. <param name="container">The container to make the registrations in.</param>
  1424. <param name="concreteType">The concrete type that will be registered.</param>
  1425. <exception cref="T:System.ArgumentNullException">Thrown when either <paramref name="container"/> or
  1426. <paramref name="concreteType"/> are null references (Nothing in VB).</exception>
  1427. <exception cref="T:System.ArgumentException">Thrown when <paramref name="concreteType"/> represents an
  1428. open generic type or is a type that can not be created by the container.
  1429. </exception>
  1430. </member>
  1431. <member name="M:SimpleInjector.Extensions.NonGenericRegistrationsExtensions.Register(SimpleInjector.Container,System.Type,System.Type)">
  1432. <summary>
  1433. Registers that a new instance of <paramref name="implementation"/> will be returned every time a
  1434. <paramref name="serviceType"/> is requested. If <paramref name="serviceType"/> and
  1435. <paramref name="implementation"/> represent the same type, the type is registered by itself.
  1436. </summary>
  1437. <param name="container">The container to make the registrations in.</param>
  1438. <param name="serviceType">The base type or interface to register.</param>
  1439. <param name="implementation">The actual type that will be returned when requested.</param>
  1440. <exception cref="T:System.ArgumentNullException">Thrown when either <paramref name="container"/>,
  1441. <paramref name="serviceType"/> or <paramref name="implementation"/> are null references (Nothing in
  1442. VB).</exception>
  1443. <exception cref="T:System.ArgumentException">Thrown when <paramref name="implementation"/> is
  1444. no sub type from <paramref name="serviceType"/>, or one of them represents an open generic type.
  1445. </exception>
  1446. </member>
  1447. <member name="M:SimpleInjector.Extensions.NonGenericRegistrationsExtensions.Register(SimpleInjector.Container,System.Type,System.Func{System.Object})">
  1448. <summary>
  1449. Registers the specified delegate that allows returning instances of <paramref name="serviceType"/>.
  1450. </summary>
  1451. <param name="container">The container to make the registrations in.</param>
  1452. <param name="serviceType">The base type or interface to register.</param>
  1453. <param name="instanceCreator">The delegate that will be used for creating new instances.</param>
  1454. <exception cref="T:System.ArgumentNullException">Thrown when either <paramref name="container"/>,
  1455. <paramref name="serviceType"/> or <paramref name="instanceCreator"/> are null references (Nothing in
  1456. VB).</exception>
  1457. <exception cref="T:System.ArgumentException">Thrown when <paramref name="serviceType"/> represents an
  1458. open generic type.</exception>
  1459. </member>
  1460. <member name="M:SimpleInjector.Extensions.NonGenericRegistrationsExtensions.RegisterAll``1(SimpleInjector.Container,System.Type[])">
  1461. <summary>
  1462. Registers an collection of <paramref name="serviceTypes"/>, which instances will be resolved when
  1463. enumerating the set returned when a collection of <typeparamref name="TService"/> objects is
  1464. requested. On enumeration the container is called for each type in the list.
  1465. </summary>
  1466. <typeparam name="TService">The base type or interface for elements in the collection.</typeparam>
  1467. <param name="container">The container to make the registrations in.</param>
  1468. <param name="serviceTypes">The collection of <see cref="T:System.Type"/> objects whose instances
  1469. will be requested from the container.</param>
  1470. <exception cref="T:System.ArgumentNullException">Thrown when either <paramref name="container"/> or
  1471. <paramref name="serviceTypes"/> are null references (Nothing in VB).
  1472. </exception>
  1473. <exception cref="T:System.ArgumentException">Thrown when <paramref name="serviceTypes"/> contains a null
  1474. (Nothing in VB) element, a generic type definition, or the <typeparamref name="TService"/> is
  1475. not assignable from one of the given <paramref name="serviceTypes"/> elements.
  1476. </exception>
  1477. </member>
  1478. <member name="M:SimpleInjector.Extensions.NonGenericRegistrationsExtensions.RegisterAll``1(SimpleInjector.Container,System.Collections.Generic.IEnumerable{System.Type})">
  1479. <summary>
  1480. Registers a collection of instances of <paramref name="serviceTypes"/> to be returned when
  1481. a collection of <typeparamref name="TService"/> objects is requested.
  1482. </summary>
  1483. <typeparam name="TService">The base type or interface for elements in the collection.</typeparam>
  1484. <param name="container">The container to make the registrations in.</param>
  1485. <param name="serviceTypes">The collection of <see cref="T:System.Type"/> objects whose instances
  1486. will be requested from the container.</param>
  1487. <exception cref="T:System.ArgumentNullException">Thrown when either <paramref name="container"/> or
  1488. <paramref name="serviceTypes"/> are null references (Nothing in VB).
  1489. </exception>
  1490. <exception cref="T:System.ArgumentException">Thrown when <paramref name="serviceTypes"/> contains a null
  1491. (Nothing in VB) element, a generic type definition, or the <typeparamref name="TService"/> is
  1492. not assignable from one of the given <paramref name="serviceTypes"/> elements.
  1493. </exception>
  1494. </member>
  1495. <member name="M:SimpleInjector.Extensions.NonGenericRegistrationsExtensions.RegisterAll(SimpleInjector.Container,System.Type,System.Collections.Generic.IEnumerable{System.Type})">
  1496. <summary>
  1497. Registers an collection of <paramref name="serviceTypes"/>, which instances will be resolved when
  1498. enumerating the set returned when a collection of <paramref name="serviceType"/> objects is
  1499. requested. On enumeration the container is called for each type in the list.
  1500. </summary>
  1501. <param name="container">The container to make the registrations in.</param>
  1502. <param name="serviceType">The base type or interface for elements in the collection.</param>
  1503. <param name="serviceTypes">The collection of <see cref="T:System.Type"/> objects whose instances
  1504. will be requested from the container.</param>
  1505. <exception cref="T:System.ArgumentNullException">Thrown when either <paramref name="container"/>,
  1506. <paramref name="serviceType"/>, or <paramref name="serviceTypes"/> are null references
  1507. (Nothing in VB).
  1508. </exception>
  1509. <exception cref="T:System.ArgumentException">Thrown when <paramref name="serviceTypes"/> contains a null
  1510. (Nothing in VB) element, a generic type definition, or the <paramref name="serviceType"/> is
  1511. not assignable from one of the given <paramref name="serviceTypes"/> elements.
  1512. </exception>
  1513. </member>
  1514. <member name="M:SimpleInjector.Extensions.NonGenericRegistrationsExtensions.RegisterAll(SimpleInjector.Container,System.Type,System.Collections.IEnumerable)">
  1515. <summary>
  1516. Registers a <paramref name="collection"/> of elements of type <paramref name="serviceType"/>.
  1517. </summary>
  1518. <param name="container">The container to make the registrations in.</param>
  1519. <param name="serviceType">The base type or interface for elements in the collection.</param>
  1520. <param name="collection">The collection of items to register.</param>
  1521. <exception cref="T:System.ArgumentNullException">Thrown when either <paramref name="container"/>,
  1522. <paramref name="serviceType"/> or <paramref name="collection"/> are null references (Nothing in
  1523. VB).</exception>
  1524. <exception cref="T:System.ArgumentException">Thrown when <paramref name="serviceType"/> represents an
  1525. open generic type.</exception>
  1526. </member>
  1527. <member name="T:SimpleInjector.Extensions.OpenGenericRegistrationExtensions">
  1528. <summary>
  1529. Provides a set of static (Shared in Visual Basic) methods for registration of open generic service
  1530. types in the <see cref="T:SimpleInjector.Container"/>.
  1531. </summary>
  1532. </member>
  1533. <member name="M:SimpleInjector.Extensions.OpenGenericRegistrationExtensions.RegisterOpenGeneric(SimpleInjector.Container,System.Type,System.Type)">
  1534. <summary>
  1535. Registers that a new instance of <paramref name="openGenericImplementation"/> will be returned
  1536. every time a <paramref name="openGenericServiceType"/> is requested.
  1537. </summary>
  1538. <example>
  1539. The following example shows the definition of a generic <b>IValidator&lt;T&gt;</b> interface
  1540. and, a <b>NullValidator&lt;T&gt;</b> implementation and a specific validator for Orders.
  1541. The registration ensures a <b>OrderValidator</b> is returned when a
  1542. <b>IValidator&lt;Order&gt;</b> is requested. For all requests for a
  1543. <b>IValidator&lt;T&gt;</b> other than a <b>IValidator&lt;Order&gt;</b>, an
  1544. implementation of <b>NullValidator&lt;T&gt;</b> will be returned.
  1545. <code lang="cs"><![CDATA[
  1546. public interface IValidator<T>
  1547. {
  1548. void Validate(T instance);
  1549. }
  1550. public class NullValidator<T> : IValidator<T>
  1551. {
  1552. public void Validate(T instance)
  1553. {
  1554. }
  1555. }
  1556. public class OrderValidator : IValidator<Order>
  1557. {
  1558. public void Validate(Order instance)
  1559. {
  1560. if (instance.Total < 0)
  1561. {
  1562. throw new ValidationException("Total can not be negative.");
  1563. }
  1564. }
  1565. }
  1566. [TestMethod]
  1567. public static void TestRegisterOpenGeneric()
  1568. {
  1569. // Arrange
  1570. var container = new Container();
  1571. container.Register<IValidator<Order>, OrderValidator>();
  1572. container.RegisterOpenGeneric(typeof(IValidator<>), typeof(NullValidator<>));
  1573. // Act
  1574. var orderValidator = container.GetInstance<IValidator<Order>>();
  1575. var customerValidator = container.GetInstance<IValidator<Customer>>();
  1576. var productValidator = container.GetInstance<IValidator<Product>>();
  1577. // Assert
  1578. Assert.IsInstanceOfType(orderValidator, typeof(OrderValidator));
  1579. Assert.IsInstanceOfType(customerValidator, typeof(NullValidator<Customer>));
  1580. Assert.IsInstanceOfType(productValidator, typeof(NullValidator<Product>));
  1581. }
  1582. ]]></code>
  1583. </example>
  1584. <param name="container">The container to make the registrations in.</param>
  1585. <param name="openGenericServiceType">The definition of the open generic service type that can be
  1586. used to retrieve instances.</param>
  1587. <param name="openGenericImplementation">The definition of the open generic implementation type
  1588. that will be returned when a <paramref name="openGenericServiceType"/> is requested.</param>
  1589. </member>
  1590. <member name="M:SimpleInjector.Extensions.OpenGenericRegistrationExtensions.RegisterSingleOpenGeneric(SimpleInjector.Container,System.Type,System.Type)">
  1591. <summary>
  1592. Registers that the same instance of <paramref name="openGenericImplementation"/> will be returned
  1593. every time a <paramref name="openGenericServiceType"/> is requested.
  1594. </summary>
  1595. <example>
  1596. The following example shows the definition of a generic <b>IValidator&lt;T&gt;</b> interface
  1597. and, a <b>NullValidator&lt;T&gt;</b> implementation and a specific validator for Orders.
  1598. The registration ensures a <b>OrderValidator</b> is returned when a
  1599. <b>IValidator&lt;Order&gt;</b> is requested. For all requests for a
  1600. <b>IValidator&lt;T&gt;</b> other than a <b>IValidator&lt;Order&gt;</b>, an
  1601. implementation of <b>NullValidator&lt;T&gt;</b> will be returned.
  1602. <code lang="cs"><![CDATA[
  1603. public interface IValidator<T>
  1604. {
  1605. void Validate(T instance);
  1606. }
  1607. public class NullValidator<T> : IValidator<T>
  1608. {
  1609. public void Validate(T instance)
  1610. {
  1611. }
  1612. }
  1613. public class OrderValidator : IValidator<Order>
  1614. {
  1615. public void Validate(Order instance)
  1616. {
  1617. if (instance.Total < 0)
  1618. {
  1619. throw new ValidationException("Total can not be negative.");
  1620. }
  1621. }
  1622. }
  1623. [TestMethod]
  1624. public static void TestRegisterOpenGeneric()
  1625. {
  1626. // Arrange
  1627. var container = new Container();
  1628. container.RegisterSingle<IValidator<Order>, OrderValidator>();
  1629. container.RegisterSingleOpenGeneric(typeof(IValidator<>), typeof(NullValidator<>));
  1630. // Act
  1631. var orderValidator = container.GetInstance<IValidator<Order>>();
  1632. var customerValidator = container.GetInstance<IValidator<Customer>>();
  1633. var productValidator = container.GetInstance<IValidator<Product>>();
  1634. // Assert
  1635. Assert.IsInstanceOfType(orderValidator, typeof(OrderValidator));
  1636. Assert.IsInstanceOfType(customerValidator, typeof(NullValidator<Customer>));
  1637. Assert.IsInstanceOfType(productValidator, typeof(NullValidator<Product>));
  1638. }
  1639. ]]></code>
  1640. </example>
  1641. <param name="container">The container to make the registrations in.</param>
  1642. <param name="openGenericServiceType">The definition of the open generic service type that can be
  1643. used to retrieve instances..</param>
  1644. <param name="openGenericImplementation">The definition of the open generic implementation type
  1645. that will be returned when a <paramref name="openGenericServiceType"/> is requested.</param>
  1646. </member>
  1647. <member name="T:SimpleInjector.Extensions.OpenGenericRegistrationExtensions.TransientOpenGenericResolver">
  1648. <summary>Resolves a given open generic type as transient.</summary>
  1649. </member>
  1650. <member name="T:SimpleInjector.Extensions.OpenGenericRegistrationExtensions.OpenGenericResolver">
  1651. <summary>Resolves a given open generic type.</summary>
  1652. </member>
  1653. <member name="T:SimpleInjector.Extensions.OpenGenericRegistrationExtensions.SingleOpenGenericResolver">
  1654. <summary>Resolves a given open generic type as singleton.</summary>
  1655. </member>
  1656. <member name="T:SimpleInjector.Extensions.StringResources">
  1657. <summary>Internal helper for string resources.</summary>
  1658. </member>
  1659. </members>
  1660. </doc>