2009-06-12 Bill Holmes <billholmes54@gmail.com>
[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     internal\r
37 #else\r
38     public\r
39 #endif\r
40     interface IObjectFactory\r
41     {\r
42         /// <summary>\r
43         ///  Registers <paramref name="implementationType" /> as an \r
44         ///  implementation for all implemented interfaces.\r
45         /// </summary>\r
46         /// <param name="implementationType">\r
47         ///  A <see cref="T:System.Type" /> which is the implementation type\r
48         ///  to register.\r
49         /// </param>\r
50         /// <remarks>\r
51         ///  Once this method has been called, \r
52         ///  <paramref name="implementationType" /> may be used in future\r
53         ///  <see cref="M:Create(Type)" /> and <see cref="M:Get(Type)" />\r
54         ///  invocations.\r
55         /// </remarks>\r
56         void Register(Type implementationType);\r
57 \r
58         /// <summary>\r
59         ///  Unregisters <paramref name="implementationType" /> as an \r
60         ///  implementation for all implemented interfaces.\r
61         /// </summary>\r
62         /// <param name="implementationType">\r
63         ///  A <see cref="T:System.Type" /> which is the implementation type\r
64         ///  to unregister.\r
65         /// </param>\r
66         /// <remarks>\r
67         ///  Once this method has been called, \r
68         ///  <paramref name="implementationType" /> will no longer be used by\r
69         ///  subsequent <see cref="M:Create(Type)" /> and \r
70         ///  <see cref="M:Get(Type)" /> invocations.\r
71         /// </remarks>\r
72         void Unregister(Type implementationType);\r
73 \r
74         /// <summary>\r
75         /// Returns an instance of a stateless class (may be a singleton)\r
76         /// </summary>\r
77         /// <returns>\r
78         ///  An instance of type <paramref name="interfaceType" />.\r
79         ///  This instance will be shared by other invocations of \r
80         ///  <c>Get()</c> with the same <param name="interfaceType" /> value.\r
81         /// </returns>\r
82         object Get(Type interfaceType);\r
83 \r
84         /// <summary>\r
85         /// Returns a new instance of the specified class (can not be a singleton)\r
86         /// </summary>\r
87         /// <returns>\r
88         ///  A new instance of type <paramref name="interfaceType" />.\r
89         ///  This instance will not be shared by other invocations of \r
90         ///  <c>Create()</c> with the same <param name="interfaceType" /> \r
91         ///  value.\r
92         /// </returns>\r
93         object Create(Type interfaceType);\r
94 \r
95         /// <summary>\r
96         /// Returns a list of types implementing the required interface\r
97         /// </summary>\r
98         /// <param name="interfaceType"></param>\r
99         /// <returns>\r
100         ///  An <see cref="T:IEnumerable{Type}" /> containing all registered \r
101         ///  implementations for the interface \r
102         ///  <paramref name="interfaceType" />.\r
103         /// </returns>\r
104         IEnumerable<Type> GetImplementations(Type interfaceType);\r
105     }\r
106 \r
107     /// <summary>\r
108     ///  Extension methods for <see cref="T:IObjectFactory" />.\r
109     /// </summary>\r
110 #if !MONO_STRICT\r
111     public\r
112 #endif\r
113     static class ObjectFactoryExtensions\r
114     {\r
115         /// <summary>\r
116         ///  Creates a new instance of <typeparamref name="T" /> from \r
117         ///  <paramref name="self" />.\r
118         /// </summary>\r
119         /// <typeparam name="T">The type to create.</typeparam>\r
120         /// <param name="self">\r
121         ///  An <see cref="T:IObjectFactory" /> to use to create a new instance\r
122         ///  of type <typeparamref name="T" />.\r
123         /// </param>\r
124         /// <returns>\r
125         ///  A newly created instance of type <typeparamref name="T" />.\r
126         /// </returns>\r
127         /// <seealso cref="M:IObjectFactory.Create(Type)"/>\r
128         public static T Create<T>(this IObjectFactory self)\r
129         {\r
130             return (T) self.Create(typeof(T));\r
131         }\r
132 \r
133         /// <summary>\r
134         ///  Gets a (possibly pre-existing) instance of \r
135         ///  <typeparamref name="T" /> from <paramref name="self" />.\r
136         /// </summary>\r
137         /// <typeparam name="T">The type to get.</typeparam>\r
138         /// <param name="self">\r
139         ///  An <see cref="T:IObjectFactory" /> to use to get an instance\r
140         ///  of type <typeparamref name="T" />.\r
141         /// </param>\r
142         /// <returns>\r
143         ///  A (possibly pre-existing) instance of type \r
144         ///  <typeparamref name="T" />.\r
145         /// </returns>\r
146         /// <seealso cref="M:IObjectFactory.Get(Type)"/>\r
147         public static T Get<T>(this IObjectFactory self)\r
148         {\r
149             return (T) self.Get(typeof(T));\r
150         }\r
151     }\r
152 }\r