Removed WCF DI Oran's approach.

This commit is contained in:
bbaia
2008-11-07 20:49:45 +00:00
parent 92bfe8b85c
commit 79817a55fc
7 changed files with 0 additions and 372 deletions

View File

@@ -71,19 +71,6 @@ namespace Spring.ServiceModel.Activation
return base.CreateServiceHost(reference, baseAddresses);
}
/// <summary>
/// Creates a SpringService for a specified type of service with a specific base address.
/// </summary>
/// <param name="serviceType">Specifies the type of service to host.</param>
/// <param name="baseAddresses">The <see cref="T:System.Array"/> of type <see cref="T:System.Uri"/> that contains the base addresses for the service hosted.</param>
/// <returns>
/// A <see cref="T:System.ServiceModel.ServiceHost"/> for the type of service specified with a specific base address.
/// </returns>
protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{
return new SpringServiceHost(serviceType, baseAddresses);
}
}
}
#endif

View File

@@ -38,21 +38,6 @@ namespace Spring.ServiceModel
/// <author>Bruno Baia</author>
public class SpringServiceHost : System.ServiceModel.ServiceHost
{
private bool useSpringServiceBehavior = false;
private IApplicationContext applicationContext;
/// <summary>
/// Gets or sets the application context.
/// </summary>
/// <value>The application context.</value>
public IApplicationContext ApplicationContext
{
get { return applicationContext; }
set { applicationContext = value; }
}
#region Constructor(s) / Destructor
/// <summary>
@@ -85,31 +70,6 @@ namespace Spring.ServiceModel
public SpringServiceHost(string serviceName, IApplicationContext applicationContext, params Uri[] baseAddresses)
: base(CreateServiceType(serviceName, applicationContext), baseAddresses)
{
ApplicationContext = applicationContext;
}
/// <summary>
/// Initializes a new instance of the <see cref="SpringServiceHost"/> class.
/// </summary>
/// <remarks>Calls the contructor with an IApplicationContext argument.</remarks>
/// <param name="serviceType">Type of the service.</param>
/// <param name="baseAddresses">The base addresses.</param>
public SpringServiceHost(Type serviceType, params Uri[] baseAddresses)
: this(serviceType, GetApplicationContext(null), baseAddresses)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="SpringServiceHost"/> class.
/// </summary>
/// <param name="serviceType">Type of the service.</param>
/// <param name="applicationContext">The application context.</param>
/// <param name="baseAddresses">The base addresses.</param>
public SpringServiceHost(Type serviceType, IApplicationContext applicationContext, params Uri[] baseAddresses)
: base(serviceType, baseAddresses)
{
useSpringServiceBehavior = true;
ApplicationContext = applicationContext;
}
private static IApplicationContext GetApplicationContext(string contextName)
@@ -137,20 +97,6 @@ namespace Spring.ServiceModel
}
#endregion
/// <summary>
/// Invoked during the transition of a communication object into the opening state.
/// Adds the SpringServiceBehavior.
/// </summary>
protected override void OnOpening()
{
if (this.useSpringServiceBehavior &&
this.Description.Behaviors.Find<SpringServiceBehavior>() == null)
{
this.Description.Behaviors.Add(new SpringServiceBehavior(ApplicationContext));
}
base.OnOpening();
}
}
}
#endif

View File

@@ -1,138 +0,0 @@
#if NET_3_0
#region License
/*
* Copyright © 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.ServiceModel;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Channels;
using Spring.Context;
using System.Globalization;
#endregion
namespace Spring.ServiceModel.Support
{
/// <summary>
/// An IInstanceProvider implementation that delegates to the Spring container to instantiate a given
/// service type. This allows for the service intstance to be configured via dependency injection and
/// have AOP advice applied
/// </summary>
/// <author>Bruno Baia</author>
public class SpringInstanceProvider : IInstanceProvider
{
private IApplicationContext applicationContext;
private Type serviceType;
/// <summary>
/// Gets or sets the application context.
/// </summary>
/// <value>The application context.</value>
public IApplicationContext ApplicationContext
{
get { return applicationContext; }
set { applicationContext = value; }
}
/// <summary>
/// Gets or sets the type of the service.
/// </summary>
/// <value>The type of the service.</value>
public Type ServiceType
{
get { return serviceType; }
set { serviceType = value; }
}
/// <summary>
/// Initializes a new instance of the <see cref="SpringInstanceProvider"/> class.
/// </summary>
/// <param name="applicationContext">The application context.</param>
public SpringInstanceProvider(IApplicationContext applicationContext)
{
ApplicationContext = applicationContext;
}
/// <summary>
/// Initializes a new instance of the <see cref="SpringInstanceProvider"/> class.
/// </summary>
/// <param name="applicationContext">The application context.</param>
/// <param name="serviceType">The type.</param>
public SpringInstanceProvider(IApplicationContext applicationContext, Type serviceType)
{
ApplicationContext = applicationContext;
ServiceType = serviceType;
}
#region IInstanceProvider Members
/// <summary>
/// Returns a service object given the specified <see cref="T:System.ServiceModel.InstanceContext"/> object.
/// </summary>
/// <param name="instanceContext">The current <see cref="T:System.ServiceModel.InstanceContext"/> object.</param>
/// <returns>A user-defined service object.</returns>
public object GetInstance(InstanceContext instanceContext)
{
return GetInstance(instanceContext, null);
}
/// <summary>
/// Returns a service object given the specified <see cref="T:System.ServiceModel.InstanceContext"/> object.
/// Delegates to the Spring container to instantiate the given object type.
/// </summary>
/// <param name="instanceContext">The current <see cref="T:System.ServiceModel.InstanceContext"/> object.</param>
/// <param name="message">The message that triggered the creation of a service object.</param>
/// <returns>The service object.</returns>
public object GetInstance(InstanceContext instanceContext, Message message)
{
string[] objectNames = ApplicationContext.GetObjectNamesForType(ServiceType);
if (objectNames.Length != 1)
{
throw new InvalidOperationException(
string.Format(
CultureInfo.InvariantCulture,
"There must exist exactly one object definition of type '{0}' in the Spring container.",
ServiceType.FullName)
);
}
return ApplicationContext.GetObject(objectNames[0]);
}
/// <summary>
/// Called when an <see cref="T:System.ServiceModel.InstanceContext"/> object recycles a service object.
/// A no-op implementation
/// </summary>
/// <param name="instanceContext">The service's instance context.</param>
/// <param name="instance">The service object to be recycled.</param>
public void ReleaseInstance(InstanceContext instanceContext, object instance)
{
}
#endregion
}
}
#endif

View File

@@ -1,157 +0,0 @@
#if NET_3_0
#region License
/*
* Copyright © 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#endregion
#region Imports
using System;
using System.Collections.ObjectModel;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using Spring.Context;
using Spring.Context.Support;
using Spring.Util;
#endregion
namespace Spring.ServiceModel.Support
{
/// <summary>
/// An implementation of IServiceBehavior that applies the <see cref="SpringInstanceProvider"/> to all endpoints.
/// </summary>
/// <author>Bruno Baia</author>
public class SpringServiceBehavior : IServiceBehavior
{
private SpringInstanceProvider springInstanceProvider;
private string contextName;
/// <summary>
/// Gets or sets the spring instance provider.
/// </summary>
/// <value>The spring instance provider.</value>
public SpringInstanceProvider InstanceProvider
{
get { return springInstanceProvider; }
}
/// <summary>
/// Gets the name of the spring context used when creating this behavior.
/// </summary>
/// <value>The name of the context.</value>
public string ContextName
{
get { return contextName; }
}
/// <summary>
/// Initializes a new instance of the <see cref="SpringServiceBehavior"/> class and initializes the
/// SpringInstanceProvider
/// </summary>
public SpringServiceBehavior() : this((string)null)
{
springInstanceProvider = new SpringInstanceProvider(ContextRegistry.GetContext());
}
/// <summary>
/// Initializes a new instance of the <see cref="SpringServiceBehavior"/> class with a given Spring
/// context name.
/// </summary>
/// <param name="contextName">Name of the context.</param>
public SpringServiceBehavior(string contextName)
{
IApplicationContext applicationContext;
if (StringUtils.IsNullOrEmpty(contextName))
{
applicationContext = ContextRegistry.GetContext();
}
else
{
applicationContext = ContextRegistry.GetContext(contextName);
}
this.contextName = contextName;
springInstanceProvider = new SpringInstanceProvider(applicationContext);
}
/// <summary>
/// Initializes a new instance of the <see cref="SpringServiceBehavior"/> class.
/// </summary>
/// <param name="applicationContext">The application context.</param>
public SpringServiceBehavior(IApplicationContext applicationContext)
{
springInstanceProvider = new SpringInstanceProvider(applicationContext);
}
#region IServiceBehavior Members
/// <summary>
/// Provides the ability to pass custom data to binding elements to support the contract implementation.
/// No-op implementation
/// </summary>
/// <param name="serviceDescription">The service description of the service.</param>
/// <param name="serviceHostBase">The host of the service.</param>
/// <param name="endpoints">The service endpoints.</param>
/// <param name="bindingParameters">Custom objects to which binding elements have access.</param>
public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase,
Collection<ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters)
{
}
/// <summary>
/// Add the SpringInstanceProvider to all endpoint dispatcher.
/// </summary>
/// <param name="serviceDescription">The service description.</param>
/// <param name="serviceHostBase">The host that is currently being built.</param>
public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
{
foreach (ChannelDispatcherBase cdb in serviceHostBase.ChannelDispatchers)
{
ChannelDispatcher cd = cdb as ChannelDispatcher;
if (cd != null)
{
foreach (EndpointDispatcher ed in cd.Endpoints)
{
InstanceProvider.ServiceType = serviceDescription.ServiceType;
ed.DispatchRuntime.InstanceProvider = InstanceProvider;
}
}
}
}
/// <summary>
/// Provides the ability to inspect the service host and the service description to confirm that the service can run successfully.
/// </summary>
/// <remarks>
/// No-op implementation
/// </remarks>
/// <param name="serviceDescription">The service description.</param>
/// <param name="serviceHostBase">The service host that is currently being constructed.</param>
public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
{
}
#endregion
}
}
#endif

View File

@@ -125,13 +125,6 @@
<Compile Include="Remoting\SaoFactoryObject.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="ServiceModel\Activation\ServiceHostFactory.cs" />
<Compile Include="ServiceModel\Activation\ServiceHostFactoryObject.cs" />
<Compile Include="ServiceModel\ServiceExporter.cs" />
<Compile Include="ServiceModel\SpringServiceHost.cs" />
<Compile Include="ServiceModel\Support\ServiceProxyTypeBuilder.cs" />
<Compile Include="ServiceModel\Support\SpringInstanceProvider.cs" />
<Compile Include="ServiceModel\Support\SpringServiceBehavior.cs" />
<Compile Include="Web\Services\WebServiceProxyFactory.cs">
<SubType>Code</SubType>
</Compile>

View File

@@ -128,8 +128,6 @@
</Compile>
<Compile Include="ServiceModel\Activation\ServiceHostFactoryObject.cs" />
<Compile Include="ServiceModel\ServiceExporter.cs" />
<Compile Include="ServiceModel\Support\SpringInstanceProvider.cs" />
<Compile Include="ServiceModel\Support\SpringServiceBehavior.cs" />
<Compile Include="ServiceModel\SpringServiceHost.cs" />
<Compile Include="ServiceModel\Support\ServiceProxyTypeBuilder.cs" />
<Compile Include="Web\Services\WebServiceProxyFactory.cs">

View File

@@ -121,7 +121,6 @@
<Compile Include="Remoting\SimpleCounter.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="ServiceModel\ServiceExporterTests.cs" />
<Compile Include="Web\Services\WebServiceProxyFactoryTests.cs" />
<EmbeddedResource Include="Data\Spring\Web\Services\rpc-literal.wsdl" />
<EmbeddedResource Include="Data\Spring\Web\Services\document-literal.wsdl" />