DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Classes | Public Member Functions | Protected Member Functions | Properties | Private Member Functions | Private Attributes | List of all members
Deveel.Data.Services.ServiceContainer Class Reference
Inheritance diagram for Deveel.Data.Services.ServiceContainer:
Deveel.Data.Services.IScope

Classes

class  RegistrationConfiguration
 
class  RegistrationWithBindingConfiguration
 

Public Member Functions

 ServiceContainer ()
 
void Dispose ()
 
IScope OpenScope (string name)
 
object Resolve (Type serviceType, object name)
 
IRegistrationConfiguration< TService > Bind< TService > ()
 
IEnumerable ResolveAll (Type serviceType)
 
void Register (ServiceRegistration registration)
 
bool Unregister (Type serviceType, object serviceName)
 

Protected Member Functions

virtual void Dispose (bool disposing)
 

Properties

string ScopeName [get, set]
 

Private Member Functions

 ServiceContainer (ServiceContainer parent, string scopeName)
 
 ~ServiceContainer ()
 
object IServiceProvider. GetService (Type serviceType)
 
void RegisterConfigurations ()
 
void RegisterConfiguration (IRegistrationConfigurationProvider provider)
 

Private Attributes

IContainer container
 
List< IRegistrationConfigurationProviderregistrationProviders
 

Detailed Description

Definition at line 24 of file ServiceContainer.cs.

Constructor & Destructor Documentation

Deveel.Data.Services.ServiceContainer.ServiceContainer ( )
inline

Definition at line 28 of file ServiceContainer.cs.

29  : this(null, null) {
30  }
Deveel.Data.Services.ServiceContainer.ServiceContainer ( ServiceContainer  parent,
string  scopeName 
)
inlineprivate

Definition at line 32 of file ServiceContainer.cs.

32  {
33  if (parent != null) {
34  container = parent.container.OpenScope(scopeName)
35  .With(rules => rules.WithDefaultReuseInsteadOfTransient(Reuse.InCurrentNamedScope(scopeName)));
36 
37  ScopeName = scopeName;
38  } else {
39  container = new Container(Rules.Default
40  .WithDefaultReuseInsteadOfTransient(Reuse.Singleton)
41  .WithoutThrowOnRegisteringDisposableTransient());
42  }
43 
44  registrationProviders = new List<IRegistrationConfigurationProvider>();
45  }
List< IRegistrationConfigurationProvider > registrationProviders
Deveel.Data.Services.ServiceContainer.~ServiceContainer ( )
inlineprivate

Definition at line 47 of file ServiceContainer.cs.

47  {
48  Dispose(false);
49  }

Member Function Documentation

IRegistrationConfiguration<TService> Deveel.Data.Services.ServiceContainer.Bind< TService > ( )
inline

Implements Deveel.Data.Services.IScope.

Definition at line 110 of file ServiceContainer.cs.

110  {
111  var config = new RegistrationConfiguration<TService>(this);
112  registrationProviders.Add(config);
113  return config;
114  }
List< IRegistrationConfigurationProvider > registrationProviders
virtual void Deveel.Data.Services.ServiceContainer.Dispose ( bool  disposing)
inlineprotectedvirtual

Definition at line 55 of file ServiceContainer.cs.

55  {
56  if (disposing) {
57  lock (this) {
58  if (container != null)
59  container.Dispose();
60  }
61  }
62 
63  container = null;
64  }
void Deveel.Data.Services.ServiceContainer.Dispose ( )
inline

Definition at line 68 of file ServiceContainer.cs.

68  {
69  Dispose(true);
70  GC.SuppressFinalize(this);
71  }
object IServiceProvider. Deveel.Data.Services.ServiceContainer.GetService ( Type  serviceType)
inlineprivate

Definition at line 51 of file ServiceContainer.cs.

51  {
52  return Resolve(serviceType, null);
53  }
object Resolve(Type serviceType, object name)
IScope Deveel.Data.Services.ServiceContainer.OpenScope ( string  name)
inline

Implements Deveel.Data.Services.IScope.

Definition at line 93 of file ServiceContainer.cs.

void Deveel.Data.Services.ServiceContainer.Register ( ServiceRegistration  registration)
inline

Implements Deveel.Data.Services.IScope.

Definition at line 128 of file ServiceContainer.cs.

128  {
129  if (registration == null)
130  throw new ArgumentNullException("registration");
131 
132  if (container == null)
133  throw new InvalidOperationException("The container was not initialized.");
134 
135  lock (this) {
136  var serviceType = registration.ServiceType;
137  var service = registration.Instance;
138  var serviceName = registration.ServiceKey;
139  var implementationType = registration.ImplementationType;
140 
141  var reuse = Reuse.Singleton;
142  if (!String.IsNullOrEmpty(ScopeName))
143  reuse = Reuse.InCurrentNamedScope(ScopeName);
144 
145  if (!String.IsNullOrEmpty(registration.Scope))
146  reuse = Reuse.InCurrentNamedScope(registration.Scope);
147 
148  if (service == null) {
149  container.Register(serviceType, implementationType, serviceKey: serviceName, reuse: reuse);
150  } else {
151  container.RegisterInstance(serviceType, service, serviceKey: serviceName, reuse: reuse);
152  }
153  }
154  }
A long string in the system.
void Deveel.Data.Services.ServiceContainer.RegisterConfiguration ( IRegistrationConfigurationProvider  provider)
inlineprivate

Definition at line 83 of file ServiceContainer.cs.

83  {
84  var registration = new ServiceRegistration(provider.ServiceType, provider.ImplementationType) {
85  Scope = provider.ScopeName,
86  ServiceKey = provider.ServiceKey,
87  Instance = provider.Instance
88  };
89 
90  Register(registration);
91  }
void Register(ServiceRegistration registration)
void Deveel.Data.Services.ServiceContainer.RegisterConfigurations ( )
inlineprivate

Definition at line 73 of file ServiceContainer.cs.

73  {
74  if (registrationProviders != null && registrationProviders.Count > 0) {
75  foreach (var provider in registrationProviders) {
76  RegisterConfiguration(provider);
77  }
78 
79  registrationProviders.Clear();
80  }
81  }
List< IRegistrationConfigurationProvider > registrationProviders
void RegisterConfiguration(IRegistrationConfigurationProvider provider)
object Deveel.Data.Services.ServiceContainer.Resolve ( Type  serviceType,
object  name 
)
inline

Implements Deveel.Data.Services.IScope.

Definition at line 98 of file ServiceContainer.cs.

98  {
99  if (serviceType == null)
100  throw new ArgumentNullException("serviceType");
101 
102  if (container == null)
103  throw new InvalidOperationException("The container was not initialized.");
104 
105  lock (this) {
106  return container.Resolve(serviceType, name, IfUnresolved.ReturnDefault);
107  }
108  }
IEnumerable Deveel.Data.Services.ServiceContainer.ResolveAll ( Type  serviceType)
inline

Implements Deveel.Data.Services.IScope.

Definition at line 116 of file ServiceContainer.cs.

116  {
117  if (serviceType == null)
118  throw new ArgumentNullException("serviceType");
119 
120  if (container == null)
121  throw new InvalidOperationException("The container was not initialized.");
122 
123  lock (this) {
124  return container.ResolveMany<object>(serviceType);
125  }
126  }
bool Deveel.Data.Services.ServiceContainer.Unregister ( Type  serviceType,
object  serviceName 
)
inline

Implements Deveel.Data.Services.IScope.

Definition at line 156 of file ServiceContainer.cs.

156  {
157  if (serviceType == null)
158  throw new ArgumentNullException("serviceType");
159 
160  if (container == null)
161  throw new InvalidOperationException("The container was not initialized.");
162 
163  lock (this) {
164  container.Unregister(serviceType, serviceName);
165  return true;
166  }
167  }

Member Data Documentation

IContainer Deveel.Data.Services.ServiceContainer.container
private

Definition at line 25 of file ServiceContainer.cs.

List<IRegistrationConfigurationProvider> Deveel.Data.Services.ServiceContainer.registrationProviders
private

Definition at line 26 of file ServiceContainer.cs.

Property Documentation

string Deveel.Data.Services.ServiceContainer.ScopeName
getsetprivate

Definition at line 66 of file ServiceContainer.cs.


The documentation for this class was generated from the following file: