1
// Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.MicroKernel
.Registration
19 using System
.Reflection
;
20 using System
.Collections
.Generic
;
23 /// Describes a set of components to register in the kernel.
27 private readonly Type basedOn
;
29 internal AllTypes(Type basedOn
)
31 this.basedOn
= basedOn
;
35 /// Prepares to register types from an assembly.
37 /// <param name="assemblyName">The assembly name.</param>
38 /// <returns>The corresponding <see cref="TypesDescriptor"/></returns>
39 public TypesDescriptor
FromAssemblyNamed(string assemblyName
)
42 String extension
= Path
.GetExtension(assemblyName
);
44 if (extension
== ".dll" || extension
== ".exe")
46 if (Path
.GetDirectoryName(assemblyName
) == AppDomain
.CurrentDomain
.BaseDirectory
)
48 assembly
= Assembly
.Load(Path
.GetFileNameWithoutExtension(assemblyName
));
52 assembly
= Assembly
.LoadFile(assemblyName
);
57 assembly
= Assembly
.Load(assemblyName
);
60 return FromAssembly(assembly
);
64 /// Prepares to register types from an assembly.
66 /// <param name="assembly">The assembly.</param>
67 /// <returns>The corresponding <see cref="TypesDescriptor"/></returns>
68 public TypesDescriptor
FromAssembly(Assembly assembly
)
72 throw new ArgumentNullException("assembly");
74 return From(assembly
.GetExportedTypes());
78 /// Prepares to register types from a list of types.
80 /// <param name="types">The list of types.</param>
81 /// <returns>The corresponding <see cref="TypesDescriptor"/></returns>
82 public TypesDescriptor
From(IEnumerable
<Type
> types
)
84 return new TypesDescriptor(basedOn
, types
);
88 /// Prepares to register types from a list of types.
90 /// <param name="types">The list of types.</param>
91 /// <returns>The corresponding <see cref="TypesDescriptor"/></returns>
92 public TypesDescriptor
Pick(IEnumerable
<Type
> types
)
94 return new TypesDescriptor(basedOn
, types
);
98 /// Prepares to register types from a list of types.
100 /// <param name="types">The list of types.</param>
101 /// <returns>The corresponding <see cref="TypesDescriptor"/></returns>
102 public TypesDescriptor
From(params Type
[] types
)
104 return new TypesDescriptor(basedOn
, types
);
108 /// Describes all the types based on <see cref="basedOn"/>
110 /// <param name="basedOn">The base type.</param>
111 /// <returns></returns>
112 public static AllTypes
Of(Type basedOn
)
114 return new AllTypes(basedOn
);
118 /// Describes all the types based on type T.
120 /// <typeparam name="T">The base type.</typeparam>
121 /// <returns></returns>
122 public static AllTypes Of
<T
>()
124 return new AllTypes(typeof(T
));
128 /// Describes any types that are supplied.
130 /// <returns></returns>
131 public static AllTypes
Pick()