Removed untyped contructor from ComponentRegistration and add a protected setter.
[castle.git] / InversionOfControl / Castle.MicroKernel / ComponentActivator / AbstractComponentActivator.cs
blob9d4698278c57d5afa7467779647a7112bb390d2b
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
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.ComponentActivator
17 using System;
19 using Castle.Core;
21 /// <summary>
22 /// Abstract implementation of <see cref="IComponentActivator"/>.
23 /// The implementors must only override the InternalCreate and
24 /// InternalDestroy methods in order to perform their creation and
25 /// destruction logic.
26 /// </summary>
27 [Serializable]
28 public abstract class AbstractComponentActivator : IComponentActivator
30 private IKernel kernel;
31 private ComponentModel model;
32 private ComponentInstanceDelegate onCreation;
33 private ComponentInstanceDelegate onDestruction;
35 /// <summary>
36 /// Constructs an AbstractComponentActivator
37 /// </summary>
38 public AbstractComponentActivator(ComponentModel model, IKernel kernel,
39 ComponentInstanceDelegate onCreation,
40 ComponentInstanceDelegate onDestruction)
42 this.model = model;
43 this.kernel = kernel;
44 this.onCreation = onCreation;
45 this.onDestruction = onDestruction;
48 public IKernel Kernel
50 get { return kernel; }
53 public ComponentModel Model
55 get { return model; }
58 public ComponentInstanceDelegate OnCreation
60 get { return onCreation; }
63 public ComponentInstanceDelegate OnDestruction
65 get { return onDestruction; }
68 #region IComponentActivator Members
70 public virtual object Create(CreationContext context)
72 object instance = InternalCreate(context);
74 onCreation(model, instance);
76 return instance;
79 public virtual void Destroy(object instance)
81 InternalDestroy(instance);
83 onDestruction(model, instance);
86 #endregion
88 protected abstract object InternalCreate(CreationContext context);
90 protected abstract void InternalDestroy(object instance);