Refactored the Kernel registration fluent interface to be more readable, better suppo...
[castle.git] / InversionOfControl / Castle.Windsor.Tests / Components / DotNet2Components.cs
blobcd899f7d4a193dac6e65d1b4f18ed15ed82ffd4a
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.
16 namespace Castle.Windsor.Tests
18 using System;
19 using System.Collections;
20 using Castle.Windsor.Tests.Components;
22 public interface IRepository<T>
24 T Get(int id);
27 public class DemoRepository<T> : IRepository<T>
29 private string name;
30 private ICache<T> cache;
32 public ICache<T> Cache
34 get { return cache; }
35 set { cache = value; }
38 public string Name
40 get { return name; }
41 set { name = value; }
44 public T Get(int id)
46 return Activator.CreateInstance<T>();
50 public class ReviewerRepository : DemoRepository<IReviewer>
52 private string name;
53 private ICache<IReviewer> cache;
55 public new ICache<IReviewer> Cache
57 get { return cache; }
58 set { cache = value; }
61 public new string Name
63 get { return name; }
64 set { name = value; }
67 public new IReviewer Get(int id)
69 return null;
73 public interface ICache<T>
75 void Put(string key, T item);
76 T Get(string key);
79 public class HashTableCache<T> : ICache<T>
81 private Hashtable hash = new Hashtable();
83 public void Put(string key, T item)
85 hash[key] = item;
88 public T Get(string key)
90 return (T) hash[key];
94 public class NullCache<T> : ICache<T>
96 public void Put(string key, T item)
100 public T Get(string key)
102 return default(T);
106 public class LoggingRepositoryDecorator<T> : IRepository<T>
108 public IRepository<T> inner;
110 public LoggingRepositoryDecorator()
114 public LoggingRepositoryDecorator(IRepository<T> inner)
116 this.inner = inner;
119 public T Get(int id)
121 Console.WriteLine("Getting {0}", id);
122 return inner.Get(id);
126 [Castle.Core.Transient]
127 public class TransientRepository<T> : IRepository<T> where T : new()
129 public T Get(int id)
131 return new T();
135 public class NeedsGenericType
137 private ICache<string> cache;
139 public NeedsGenericType(ICache<string> cache)
141 this.cache = cache;