2009-07-11 Michael Barker <mike@middlesoft.co.uk>
[mono.git] / mcs / class / System.Data.Linq / src / DbLinq / Factory / IObjectFactory.cs
1 #region MIT license\r
2 // \r
3 // MIT license\r
4 //\r
5 // Copyright (c) 2007-2008 Jiri Moudry, Pascal Craponne\r
6 // \r
7 // Permission is hereby granted, free of charge, to any person obtaining a copy\r
8 // of this software and associated documentation files (the "Software"), to deal\r
9 // in the Software without restriction, including without limitation the rights\r
10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
11 // copies of the Software, and to permit persons to whom the Software is\r
12 // furnished to do so, subject to the following conditions:\r
13 // \r
14 // The above copyright notice and this permission notice shall be included in\r
15 // all copies or substantial portions of the Software.\r
16 // \r
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
23 // THE SOFTWARE.\r
24 // \r
25 #endregion\r
26 using System;\r
27 using System.Collections.Generic;\r
28 \r
29 namespace DbLinq.Factory\r
30 {\r
31     /// <summary>\r
32     /// The object factory is the start point for DbLinq main factory.\r
33     /// See ObjectFactory.Current for details\r
34     /// </summary>\r
35 #if !MONO_STRICT\r
36     public\r
37 #endif\r
38     interface IObjectFactory\r
39     {\r
40         /// <summary>\r
41         ///  Registers <paramref name="implementationType" /> as an \r
42         ///  implementation for all implemented interfaces.\r
43         /// </summary>\r
44         /// <param name="implementationType">\r
45         ///  A <see cref="T:System.Type" /> which is the implementation type\r
46         ///  to register.\r
47         /// </param>\r
48         /// <remarks>\r
49         ///  Once this method has been called, \r
50         ///  <paramref name="implementationType" /> may be used in future\r
51         ///  <see cref="M:Create(Type)" /> and <see cref="M:Get(Type)" />\r
52         ///  invocations.\r
53         /// </remarks>\r
54         void Register(Type implementationType);\r
55 \r
56         /// <summary>\r
57         ///  Unregisters <paramref name="implementationType" /> as an \r
58         ///  implementation for all implemented interfaces.\r
59         /// </summary>\r
60         /// <param name="implementationType">\r
61         ///  A <see cref="T:System.Type" /> which is the implementation type\r
62         ///  to unregister.\r
63         /// </param>\r
64         /// <remarks>\r
65         ///  Once this method has been called, \r
66         ///  <paramref name="implementationType" /> will no longer be used by\r
67         ///  subsequent <see cref="M:Create(Type)" /> and \r
68         ///  <see cref="M:Get(Type)" /> invocations.\r
69         /// </remarks>\r
70         void Unregister(Type implementationType);\r
71 \r
72         /// <summary>\r
73         /// Returns an instance of a stateless class (may be a singleton)\r
74         /// </summary>\r
75         /// <returns>\r
76         ///  An instance of type <paramref name="interfaceType" />.\r
77         ///  This instance will be shared by other invocations of \r
78         ///  <c>Get()</c> with the same <param name="interfaceType" /> value.\r
79         /// </returns>\r
80         object Get(Type interfaceType);\r
81 \r
82         /// <summary>\r
83         /// Returns a new instance of the specified class (can not be a singleton)\r
84         /// </summary>\r
85         /// <returns>\r
86         ///  A new instance of type <paramref name="interfaceType" />.\r
87         ///  This instance will not be shared by other invocations of \r
88         ///  <c>Create()</c> with the same <param name="interfaceType" /> \r
89         ///  value.\r
90         /// </returns>\r
91         object Create(Type interfaceType);\r
92 \r
93         /// <summary>\r
94         /// Returns a list of types implementing the required interface\r
95         /// </summary>\r
96         /// <param name="interfaceType"></param>\r
97         /// <returns>\r
98         ///  An <see cref="T:IEnumerable{Type}" /> containing all registered \r
99         ///  implementations for the interface \r
100         ///  <paramref name="interfaceType" />.\r
101         /// </returns>\r
102         IEnumerable<Type> GetImplementations(Type interfaceType);\r
103     }\r
104 \r
105     /// <summary>\r
106     ///  Extension methods for <see cref="T:IObjectFactory" />.\r
107     /// </summary>\r
108 #if !MONO_STRICT\r
109     public\r
110 #endif\r
111     static class ObjectFactoryExtensions\r
112     {\r
113         /// <summary>\r
114         ///  Creates a new instance of <typeparamref name="T" /> from \r
115         ///  <paramref name="self" />.\r
116         /// </summary>\r
117         /// <typeparam name="T">The type to create.</typeparam>\r
118         /// <param name="self">\r
119         ///  An <see cref="T:IObjectFactory" /> to use to create a new instance\r
120         ///  of type <typeparamref name="T" />.\r
121         /// </param>\r
122         /// <returns>\r
123         ///  A newly created instance of type <typeparamref name="T" />.\r
124         /// </returns>\r
125         /// <seealso cref="M:IObjectFactory.Create(Type)"/>\r
126         public static T Create<T>(this IObjectFactory self)\r
127         {\r
128             return (T) self.Create(typeof(T));\r
129         }\r
130 \r
131         /// <summary>\r
132         ///  Gets a (possibly pre-existing) instance of \r
133         ///  <typeparamref name="T" /> from <paramref name="self" />.\r
134         /// </summary>\r
135         /// <typeparam name="T">The type to get.</typeparam>\r
136         /// <param name="self">\r
137         ///  An <see cref="T:IObjectFactory" /> to use to get an instance\r
138         ///  of type <typeparamref name="T" />.\r
139         /// </param>\r
140         /// <returns>\r
141         ///  A (possibly pre-existing) instance of type \r
142         ///  <typeparamref name="T" />.\r
143         /// </returns>\r
144         /// <seealso cref="M:IObjectFactory.Get(Type)"/>\r
145         public static T Get<T>(this IObjectFactory self)\r
146         {\r
147             return (T) self.Get(typeof(T));\r
148         }\r
149     }\r
150 }\r