all services are singleton by default.

This commit is contained in:
Keivan Beigi 2013-05-29 18:33:20 -07:00
parent 8bdf8c31f0
commit 763df726f0
12 changed files with 5 additions and 34 deletions

View File

@ -19,7 +19,6 @@ using TinyIoC;
namespace NzbDrone.Api namespace NzbDrone.Api
{ {
[Singleton]
public class NancyBootstrapper : TinyIoCNancyBootstrapper public class NancyBootstrapper : TinyIoCNancyBootstrapper
{ {
private readonly TinyIoCContainer _tinyIoCContainer; private readonly TinyIoCContainer _tinyIoCContainer;

View File

@ -1,12 +1,10 @@
using System; using System;
using System.IO; using System.IO;
using Microsoft.AspNet.SignalR.Json; using Microsoft.AspNet.SignalR.Json;
using NzbDrone.Common.Composition;
using NzbDrone.Common.Serializer; using NzbDrone.Common.Serializer;
namespace NzbDrone.Api.SignalR namespace NzbDrone.Api.SignalR
{ {
[Singleton]
public class Serializer : IJsonSerializer public class Serializer : IJsonSerializer
{ {
private readonly JsonNetSerializer _signalRSerializer = new JsonNetSerializer(); private readonly JsonNetSerializer _signalRSerializer = new JsonNetSerializer();

View File

@ -86,9 +86,9 @@ namespace NzbDrone.Common.Composition
_container.Register(registrationType, instance); _container.Register(registrationType, instance);
} }
public void RegisterAll(Type registrationType, IEnumerable<Type> implementationList) public void RegisterAllAsSingleton(Type registrationType, IEnumerable<Type> implementationList)
{ {
_container.RegisterMultiple(registrationType, implementationList); _container.RegisterMultiple(registrationType, implementationList).AsSingleton();
} }
public bool IsTypeRegistered(Type type) public bool IsTypeRegistered(Type type)

View File

@ -64,22 +64,12 @@ namespace NzbDrone.Common.Composition
var impl = implementations.Single(); var impl = implementations.Single();
Trace.WriteLine(string.Format("Registering {0} -> {1}", contractType.FullName, impl.Name)); Trace.WriteLine(string.Format("Registering {0} -> {1}", contractType.FullName, impl.Name));
Container.RegisterSingleton(contractType, impl);
if (impl.HasAttribute<SingletonAttribute>())
{
Container.RegisterSingleton(contractType, impl);
}
else
{
Container.Register(contractType, impl);
}
} }
else else
{ {
Trace.WriteLine(string.Format("Registering {0} -> {1}", contractType.FullName, implementations.Count)); Trace.WriteLine(string.Format("Registering {0} -> {1}", contractType.FullName, implementations.Count));
Container.RegisterAllAsSingleton(contractType, implementations);
Container.RegisterAll(contractType, implementations);
} }
} }

View File

@ -24,7 +24,7 @@ namespace NzbDrone.Common.Composition
IEnumerable<T> ResolveAll<T>() where T : class; IEnumerable<T> ResolveAll<T>() where T : class;
IEnumerable<object> ResolveAll(Type type); IEnumerable<object> ResolveAll(Type type);
void Register(Type registrationType, object instance); void Register(Type registrationType, object instance);
void RegisterAll(Type registrationType, IEnumerable<Type> implementationList); void RegisterAllAsSingleton(Type registrationType, IEnumerable<Type> implementationList);
bool IsTypeRegistered(Type type); bool IsTypeRegistered(Type type);
IEnumerable<Type> GetImplementations(Type contractType); IEnumerable<Type> GetImplementations(Type contractType);

View File

@ -1,8 +0,0 @@
using System;
namespace NzbDrone.Common.Composition
{
public class SingletonAttribute : Attribute
{
}
}

View File

@ -3,13 +3,11 @@ using System.Linq;
using System.Reflection; using System.Reflection;
using System.Threading.Tasks; using System.Threading.Tasks;
using NLog; using NLog;
using NzbDrone.Common.Composition;
using NzbDrone.Common.EnsureThat; using NzbDrone.Common.EnsureThat;
using NzbDrone.Common.Serializer; using NzbDrone.Common.Serializer;
namespace NzbDrone.Common.Messaging namespace NzbDrone.Common.Messaging
{ {
[Singleton]
public class MessageAggregator : IMessageAggregator public class MessageAggregator : IMessageAggregator
{ {
private readonly Logger _logger; private readonly Logger _logger;

View File

@ -83,7 +83,6 @@
<Compile Include="Cache\ICached.cs" /> <Compile Include="Cache\ICached.cs" />
<Compile Include="Composition\Container.cs" /> <Compile Include="Composition\Container.cs" />
<Compile Include="Composition\IContainer.cs" /> <Compile Include="Composition\IContainer.cs" />
<Compile Include="Composition\SingletonAttribute.cs" />
<Compile Include="Composition\ContainerBuilderBase.cs" /> <Compile Include="Composition\ContainerBuilderBase.cs" />
<Compile Include="EnsureThat\Ensure.cs" /> <Compile Include="EnsureThat\Ensure.cs" />
<Compile Include="EnsureThat\EnsureBoolExtensions.cs" /> <Compile Include="EnsureThat\EnsureBoolExtensions.cs" />

View File

@ -2,7 +2,6 @@
using System.Data.SQLite; using System.Data.SQLite;
using Marr.Data; using Marr.Data;
using Marr.Data.Reflection; using Marr.Data.Reflection;
using NzbDrone.Common.Composition;
using NzbDrone.Core.Datastore.Migration.Framework; using NzbDrone.Core.Datastore.Migration.Framework;
@ -13,7 +12,6 @@ namespace NzbDrone.Core.Datastore
IDatabase Create(string dbPath, MigrationType migrationType = MigrationType.Main); IDatabase Create(string dbPath, MigrationType migrationType = MigrationType.Main);
} }
[Singleton]
public class DbFactory : IDbFactory public class DbFactory : IDbFactory
{ {
private readonly IMigrationController _migrationController; private readonly IMigrationController _migrationController;

View File

@ -5,7 +5,6 @@ using NzbDrone.Common.Composition;
namespace NzbDrone.Core.Datastore.Migration.Framework namespace NzbDrone.Core.Datastore.Migration.Framework
{ {
[Singleton]
public class MigrationLogger : IAnnouncer public class MigrationLogger : IAnnouncer
{ {
private readonly Logger _logger; private readonly Logger _logger;

View File

@ -9,7 +9,6 @@ using Timer = System.Timers.Timer;
namespace NzbDrone.Core.Jobs namespace NzbDrone.Core.Jobs
{ {
[Singleton]
public class Scheduler : public class Scheduler :
IHandle<ApplicationStartedEvent>, IHandle<ApplicationStartedEvent>,
IHandle<ApplicationShutdownRequested> IHandle<ApplicationShutdownRequested>

View File

@ -9,7 +9,6 @@ using IServiceProvider = NzbDrone.Common.IServiceProvider;
namespace NzbDrone namespace NzbDrone
{ {
[Singleton]
public class Router public class Router
{ {
private readonly INzbDroneServiceFactory _nzbDroneServiceFactory; private readonly INzbDroneServiceFactory _nzbDroneServiceFactory;