// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.md in the project root for license information. using System; using System.Globalization; namespace Microsoft.AspNet.SignalR.Hosting { /// /// Responsible for creating instances. /// public class PersistentConnectionFactory { private readonly IDependencyResolver _resolver; /// /// Creates a new instance of the class. /// /// The dependency resolver to use for when creating the . public PersistentConnectionFactory(IDependencyResolver resolver) { if (resolver == null) { throw new ArgumentNullException("resolver"); } _resolver = resolver; } /// /// Creates an instance of the specified type using the dependency resolver or the type's default constructor. /// /// The type of to create. /// An instance of a . public PersistentConnection CreateInstance(Type connectionType) { if (connectionType == null) { throw new ArgumentNullException("connectionType"); } var connection = (_resolver.Resolve(connectionType) ?? Activator.CreateInstance(connectionType)) as PersistentConnection; if (connection == null) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.Error_IsNotA, connectionType.FullName, typeof(PersistentConnection).FullName)); } return connection; } } }