Browse Source

Made central registry of AddInManager's service instances more flexible to support unit testing.

pull/32/head
Andreas Weizel 13 years ago
parent
commit
ad212ed0b7
  1. 3
      src/AddIns/Misc/AddInManager2/Project/AddInManager2.csproj
  2. 59
      src/AddIns/Misc/AddInManager2/Project/Src/AddInManager.cs
  3. 93
      src/AddIns/Misc/AddInManager2/Project/Src/AddInManagerServices.cs
  4. 2
      src/AddIns/Misc/AddInManager2/Project/Src/Commands.cs
  5. 33
      src/AddIns/Misc/AddInManager2/Project/Src/Model/Interfaces/IAddInManagerServices.cs
  6. 22
      src/AddIns/Misc/AddInManager2/Project/Src/Model/Model.cs

3
src/AddIns/Misc/AddInManager2/Project/AddInManager2.csproj

@ -88,7 +88,7 @@ @@ -88,7 +88,7 @@
<Link>Configuration\GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Configuration\AssemblyInfo.cs" />
<Compile Include="Src\AddInManager.cs" />
<Compile Include="Src\AddInManagerServices.cs" />
<Compile Include="Src\AddInManagerTask.cs" />
<Compile Include="Src\BooleanToFontWeightConverter.cs" />
<Compile Include="Src\Commands.cs" />
@ -97,6 +97,7 @@ @@ -97,6 +97,7 @@
<Compile Include="Src\Model\AcceptLicensesEventArgs.cs" />
<Compile Include="Src\Model\AddInDependency.cs" />
<Compile Include="Src\Model\AddInInstallationEventArgs.cs" />
<Compile Include="Src\Model\Interfaces\IAddInManagerServices.cs" />
<Compile Include="Src\Model\ManagedAddIn.cs" />
<Compile Include="Src\Model\Interfaces\IAddInManagerEvents.cs" />
<Compile Include="Src\Model\Interfaces\IAddInPackage.cs" />

59
src/AddIns/Misc/AddInManager2/Project/Src/AddInManager.cs

@ -1,59 +0,0 @@ @@ -1,59 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.AddInManager2.Model;
namespace ICSharpCode.AddInManager2
{
/// <summary>
/// Container for public services of AddInManager AddIn.
/// </summary>
public class AddInManager
{
private static readonly AddInManagerEvents _events;
private static readonly PackageRepositories _repositories;
private static readonly AddInSetup _setup;
private static readonly NuGetPackageManager _nuGet;
static AddInManager()
{
_events = new AddInManagerEvents();
_repositories = new PackageRepositories();
_nuGet = new NuGetPackageManager(_repositories, _events);
_setup = new AddInSetup(_events, _nuGet);
}
public static IAddInManagerEvents Events
{
get
{
return _events;
}
}
public static IPackageRepositories Repositories
{
get
{
return _repositories;
}
}
public static IAddInSetup Setup
{
get
{
return _setup;
}
}
public static INuGetPackageManager NuGet
{
get
{
return _nuGet;
}
}
}
}

93
src/AddIns/Misc/AddInManager2/Project/Src/AddInManagerServices.cs

@ -0,0 +1,93 @@ @@ -0,0 +1,93 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.AddInManager2.Model;
using ICSharpCode.AddInManager2.Model.Interfaces;
namespace ICSharpCode.AddInManager2
{
/// <summary>
/// Container for public services of AddInManager AddIn.
/// </summary>
public class AddInManagerServices
{
private class AddInManagerServiceContainer : IAddInManagerServices
{
public IAddInManagerEvents Events
{
get;
set;
}
public IPackageRepositories Repositories
{
get;
set;
}
public IAddInSetup Setup
{
get;
set;
}
public INuGetPackageManager NuGet
{
get;
set;
}
}
private static AddInManagerServiceContainer _container;
static AddInManagerServices()
{
_container = new AddInManagerServiceContainer();
_container.Events = new AddInManagerEvents();
_container.Repositories = new PackageRepositories();
_container.NuGet = new NuGetPackageManager(_container.Repositories, _container.Events);
_container.Setup = new AddInSetup(_container.Events, _container.NuGet);
}
public static IAddInManagerEvents Events
{
get
{
return _container.Events;
}
}
public static IPackageRepositories Repositories
{
get
{
return _container.Repositories;
}
}
public static IAddInSetup Setup
{
get
{
return _container.Setup;
}
}
public static INuGetPackageManager NuGet
{
get
{
return _container.NuGet;
}
}
public static IAddInManagerServices Services
{
get
{
return _container;
}
}
}
}

2
src/AddIns/Misc/AddInManager2/Project/Src/Commands.cs

@ -38,7 +38,7 @@ namespace ICSharpCode.AddInManager2 @@ -38,7 +38,7 @@ namespace ICSharpCode.AddInManager2
SD.ResourceService.RegisterStrings("ICSharpCode.AddInManager2.Resources.StringResources", GetType().Assembly);
// Remove all unreferenced NuGet packages
AddInManager.Setup.RemoveUnreferencedNuGetPackages();
AddInManagerServices.Setup.RemoveUnreferencedNuGetPackages();
}
}
}

33
src/AddIns/Misc/AddInManager2/Project/Src/Model/Interfaces/IAddInManagerServices.cs

@ -0,0 +1,33 @@ @@ -0,0 +1,33 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
namespace ICSharpCode.AddInManager2.Model.Interfaces
{
/// <summary>
/// Basic interface providing instances to all services of AddInManager AddIn.
/// </summary>
public interface IAddInManagerServices
{
IAddInManagerEvents Events
{
get;
}
IPackageRepositories Repositories
{
get;
}
IAddInSetup Setup
{
get;
}
INuGetPackageManager NuGet
{
get;
}
}
}

22
src/AddIns/Misc/AddInManager2/Project/Src/Model/Model.cs

@ -4,11 +4,14 @@ @@ -4,11 +4,14 @@
using System;
using System.ComponentModel;
using System.Linq.Expressions;
using ICSharpCode.AddInManager2.Model.Interfaces;
namespace ICSharpCode.AddInManager2.Model
{
public abstract class Model<TModel> : INotifyPropertyChanged
{
private IAddInManagerServices _addInManager = null;
public event PropertyChangedEventHandler PropertyChanged;
public string PropertyChangedFor<TProperty>(Expression<Func<TModel, TProperty>> expression)
@ -39,5 +42,24 @@ namespace ICSharpCode.AddInManager2.Model @@ -39,5 +42,24 @@ namespace ICSharpCode.AddInManager2.Model
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
protected IAddInManagerServices AddInManager
{
get
{
if (_addInManager == null)
{
return AddInManagerServices.Services;
}
else
{
return _addInManager;
}
}
set
{
_addInManager = value;
}
}
}
}

Loading…
Cancel
Save