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
.ComponentActivator
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.
28 public abstract class AbstractComponentActivator
: IComponentActivator
30 private IKernel kernel
;
31 private ComponentModel model
;
32 private ComponentInstanceDelegate onCreation
;
33 private ComponentInstanceDelegate onDestruction
;
36 /// Constructs an AbstractComponentActivator
38 public AbstractComponentActivator(ComponentModel model
, IKernel kernel
,
39 ComponentInstanceDelegate onCreation
,
40 ComponentInstanceDelegate onDestruction
)
44 this.onCreation
= onCreation
;
45 this.onDestruction
= onDestruction
;
50 get { return kernel; }
53 public ComponentModel 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
);
79 public virtual void Destroy(object instance
)
81 InternalDestroy(instance
);
83 onDestruction(model
, instance
);
88 protected abstract object InternalCreate(CreationContext context
);
90 protected abstract void InternalDestroy(object instance
);