Line data Source code
1 : #region Copyright
2 : // // -----------------------------------------------------------------------
3 : // // <copyright company="Chinchilla Software Limited">
4 : // // Copyright Chinchilla Software Limited. All rights reserved.
5 : // // </copyright>
6 : // // -----------------------------------------------------------------------
7 : #endregion
8 :
9 : using System;
10 : using Cqrs.Configuration;
11 :
12 : namespace Cqrs.Repositories.Queries
13 : {
14 : /// <summary>
15 : /// A factory to create new instances of <see cref="ResultQuery{TQueryStrategy,TData}"/>.
16 : /// </summary>
17 : public class QueryFactory : IQueryFactory
18 1 : {
19 : /// <summary>
20 : /// Gets or sets the <see cref="IDependencyResolver"/>.
21 : /// </summary>
22 : protected IDependencyResolver DependencyResolver { get; private set; }
23 :
24 : /// <summary>
25 : /// Instantiates a new instance of <see cref="QueryFactory"/>
26 : /// </summary>
27 1 : public QueryFactory(IDependencyResolver dependencyResolver)
28 : {
29 : DependencyResolver = dependencyResolver;
30 : }
31 :
32 : /// <summary>
33 : /// Creates a new <see cref="ISingleResultQuery{TQueryStrategy,TData}"/>
34 : /// using <see cref="DependencyResolver"/> to create a new <typeparamref name="TUserQueryStrategy"/>.
35 : /// </summary>
36 : /// <typeparam name="TUserQueryStrategy">The <see cref="Type"/> of <see cref="IQueryStrategy"/> it will use.</typeparam>
37 : /// <typeparam name="TData">The <see cref="Type"/> of data the <see cref="ISingleResultQuery{TQueryStrategy,TData}"/> will operate on.</typeparam>
38 1 : public ISingleResultQuery<TUserQueryStrategy, TData> CreateNewSingleResultQuery<TUserQueryStrategy, TData>()
39 : where TUserQueryStrategy : IQueryStrategy
40 : {
41 : var queryStrategy = DependencyResolver.Resolve<TUserQueryStrategy>();
42 : return new SingleResultQuery<TUserQueryStrategy, TData>
43 : {
44 : QueryStrategy = queryStrategy
45 : };
46 : }
47 :
48 : /// <summary>
49 : /// Creates a new <see cref="ICollectionResultQuery{TQueryStrategy,TData}"/>
50 : /// using <see cref="DependencyResolver"/> to create a new <typeparamref name="TUserQueryStrategy"/>.
51 : /// </summary>
52 : /// <typeparam name="TUserQueryStrategy">The <see cref="Type"/> of <see cref="IQueryStrategy"/> it will use.</typeparam>
53 : /// <typeparam name="TData">The <see cref="Type"/> of data the <see cref="ISingleResultQuery{TQueryStrategy,TData}"/> will operate on.</typeparam>
54 1 : public ICollectionResultQuery<TUserQueryStrategy, TData> CreateNewCollectionResultQuery<TUserQueryStrategy, TData>()
55 : where TUserQueryStrategy : IQueryStrategy
56 : {
57 : var queryStrategy = DependencyResolver.Resolve<TUserQueryStrategy>();
58 : return new CollectionResultQuery<TUserQueryStrategy, TData>
59 : {
60 : QueryStrategy = queryStrategy
61 : };
62 : }
63 : }
64 : }
|