1 /** 2 License: 3 Boost Software License - Version 1.0 - August 17th, 2003 4 5 Permission is hereby granted, free of charge, to any person or organization 6 obtaining a copy of the software and accompanying documentation covered by 7 this license (the "Software") to use, reproduce, display, distribute, 8 execute, and transmit the Software, and to prepare derivative works of the 9 Software, and to permit third-parties to whom the Software is furnished to 10 do so, all subject to the following: 11 12 The copyright notices in the Software and this entire statement, including 13 the above license grant, this restriction and the following disclaimer, 14 must be included in all copies of the Software, in whole or in part, and 15 all derivative works of the Software, unless such copies or derivative 16 works are solely in the form of machine-executable object code generated by 17 a source language processor. 18 19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 22 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 23 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 24 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 DEALINGS IN THE SOFTWARE. 26 27 Authors: 28 aermicioi 29 **/ 30 module aermicioi.aedi.configurer.register.container; 31 32 import aermicioi.aedi.container; 33 import std.traits; 34 import std.meta; 35 import aermicioi.util.traits; 36 37 /** 38 Create a singleton container 39 40 Returns: 41 SingletonContainer 42 **/ 43 auto singleton() { 44 return new SingletonContainer(); 45 } 46 47 /** 48 Create a prototype container 49 50 Returns: 51 PrototypeContainer 52 **/ 53 auto prototype() { 54 return new PrototypeContainer(); 55 } 56 57 /** 58 Create a container for values 59 60 Returns: 61 ValueContainer 62 **/ 63 auto values() { 64 return new ValueContainer(); 65 } 66 67 /** 68 Wrap up a container into switchable container. 69 70 Wraps up a container to provide switching capabilites to it. 71 72 Returns: 73 SwitchableContainer!T 74 **/ 75 auto switchable(T : Container)(auto ref T container) { 76 return (new SwitchableContainer!T()).decorated(container); 77 } 78 79 /** 80 Wrap up a container into subscribable container. 81 82 Wraps up a container to provide events to subscribe to. 83 84 Returns: 85 SubscribableContainer!T 86 **/ 87 auto subscribable(T : Container)(auto ref T container) { 88 return (new SubscribableContainer!T()).decorated(container); 89 } 90 91 /** 92 Wrap up a container into a type based container. 93 94 Wraps up container into a container that adds capability to 95 search for a component based on it's type, or implemented 96 hierarchy of classes and interfaces. 97 98 Returns: 99 TypeBasedContainer!T 100 **/ 101 auto typed(T : Container)(auto ref T container) { 102 return (new TypeBasedContainer!T()).decorated(container); 103 } 104 105 /** 106 Wrap up a container into aliasing container. 107 108 Wraps up container into aliasing container which provides 109 capabilities to alias identity of components in original container. 110 111 Returns: 112 AliasingContainer!T 113 **/ 114 auto aliasing(T)(auto ref T container) { 115 return (new AliasingContainer!T()).decorated(container); 116 } 117 118 /** 119 Wraps up several containers into one. 120 121 Params: 122 containers = a list of containers to be used together 123 124 Returns: 125 TupleContainer!T 126 **/ 127 auto container(T...)(T containers) 128 if (allSatisfy!(partialSuffixed!(isDerived, Container), T)) { 129 return new TupleContainer!T(containers); 130 } 131 132 /** 133 Wraps up several containers into one. 134 135 Params: 136 managed = first container managed by aggregate one 137 identity = identity of container by which it is possible to identify it 138 manageds = a set of containers in pairs of (managed, identity) 139 140 Returns: 141 TupleContainer!T 142 **/ 143 auto aggregate(T...)(Container managed, string identity, T manageds) { 144 AggregateContainer container = new AggregateContainer; 145 146 return container.aggregate(managed, identity, manageds); 147 } 148 149 private { 150 151 auto aggregate(T...)(AggregateContainer container, Container managed, string identity, T manageds) { 152 container.set(managed, identity); 153 154 static if (T.length > 1) { 155 container.aggregate(manageds); 156 } 157 return container; 158 } 159 }