Skip to content

Commit

Permalink
Allow custom UIs by exporting the IoC kernel to other DLLs
Browse files Browse the repository at this point in the history
  • Loading branch information
anaisbetts committed Jul 3, 2012
1 parent dea6615 commit 623905c
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Shimmer.Client/Shimmer.Client.csproj
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
<Compile Include="WiXUi\EngineWrapper.cs" /> <Compile Include="WiXUi\EngineWrapper.cs" />
<Compile Include="IAppSetup.cs" /> <Compile Include="IAppSetup.cs" />
<Compile Include="IUpdateManager.cs" /> <Compile Include="IUpdateManager.cs" />
<Compile Include="WiXUi\IWiXCustomUi.cs" />
<Compile Include="WiXUi\IWiXEvents.cs" /> <Compile Include="WiXUi\IWiXEvents.cs" />
<Compile Include="WiXUi\IWixUiBootstrapper.cs" /> <Compile Include="WiXUi\IWixUiBootstrapper.cs" />
<Compile Include="PostInstallInfo.cs" /> <Compile Include="PostInstallInfo.cs" />
Expand Down
13 changes: 13 additions & 0 deletions src/Shimmer.Client/WiXUi/IWiXCustomUi.cs
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TinyIoC;

namespace Shimmer.Client.WiXUi
{
interface IWiXCustomUi
{
void RegisterTypes(TinyIoCContainer kernel);
}
}
8 changes: 7 additions & 1 deletion src/Shimmer.Tests/Shimmer.Tests.csproj
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -157,8 +157,14 @@
<Project>{3D17D46A-A411-4922-B932-9EBE2AAE0ED7}</Project> <Project>{3D17D46A-A411-4922-B932-9EBE2AAE0ED7}</Project>
<Name>Shimmer.Core</Name> <Name>Shimmer.Core</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\Shimmer.WiXUi\Shimmer.WiXUi.csproj">
<Project>{5f84c302-8216-47e0-b822-b83b65d81309}</Project>
<Name>Shimmer.WiXUi</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="WiXUi\" />
</ItemGroup> </ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\nuget.targets" /> <Import Project="$(SolutionDir)\.nuget\nuget.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
22 changes: 22 additions & 0 deletions src/Shimmer.Tests/TestHelpers/IntegrationTestHelper.cs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Reactive; using System.Reactive;
using System.Reactive.Disposables; using System.Reactive.Disposables;
using System.Reactive.Linq; using System.Reactive.Linq;
using System.Threading;
using Shimmer.Core; using Shimmer.Core;
using ReactiveUI; using ReactiveUI;


Expand Down Expand Up @@ -35,5 +36,26 @@ public static bool SkipTestOnXPAndVista()
int osVersion = Environment.OSVersion.Version.Major*100 + Environment.OSVersion.Version.Minor; int osVersion = Environment.OSVersion.Version.Major*100 + Environment.OSVersion.Version.Minor;
return (osVersion < 601); return (osVersion < 601);
} }

public static void RunBlockAsSTA(Action block)
{
Exception ex = null;
var t = new Thread(() => {
try {
block();
} catch (Exception e) {
ex = e;
}
});

t.SetApartmentState(ApartmentState.STA);
t.Start();
t.Join();

if (ex != null) {
// NB: If we don't do this, the test silently passes
throw new Exception("", ex);
}
}
} }
} }
1 change: 1 addition & 0 deletions src/Shimmer.WiXUi/App.cs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.Tools.WindowsInstallerXml.Bootstrapper; using Microsoft.Tools.WindowsInstallerXml.Bootstrapper;
using ReactiveUI.Routing; using ReactiveUI.Routing;
using Shimmer.Client; using Shimmer.Client;
using Shimmer.Client.WiXUi;
using Shimmer.Core; using Shimmer.Core;
using Shimmer.WiXUi.ViewModels; using Shimmer.WiXUi.ViewModels;
using Shimmer.WiXUi.Views; using Shimmer.WiXUi.Views;
Expand Down
37 changes: 37 additions & 0 deletions src/Shimmer.WiXUi/ViewModels/WixUiBootstrapper.cs
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,11 @@
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using ReactiveUI; using ReactiveUI;
using ReactiveUI.Routing; using ReactiveUI.Routing;
using Shimmer.Client; using Shimmer.Client;
using Shimmer.Client.WiXUi;
using TinyIoC; using TinyIoC;


namespace Shimmer.WiXUi.ViewModels namespace Shimmer.WiXUi.ViewModels
Expand All @@ -21,11 +26,43 @@ public WixUiBootstrapper(IWiXEvents wixEvents, TinyIoCContainer testKernel = nul
Router = router ?? new RoutingState(); Router = router ?? new RoutingState();
WiXEvents = wixEvents; WiXEvents = wixEvents;


registerExtensionDlls(Kernel);

RxApp.ConfigureServiceLocator( RxApp.ConfigureServiceLocator(
(type, contract) => Kernel.Resolve(type, contract), (type, contract) => Kernel.Resolve(type, contract),
(type, contract) => Kernel.ResolveAll(type)); (type, contract) => Kernel.ResolveAll(type));
} }


void registerExtensionDlls(TinyIoCContainer kernel)
{
var di = new DirectoryInfo(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));

var extensions = di.GetFiles("*.dll")
.Where(x => x.FullName != Assembly.GetExecutingAssembly().Location)
.SelectMany(x => {
try {
return new[] {Assembly.LoadFile(x.FullName)};
} catch (Exception ex) {
this.Log().WarnException("Couldn't load " + x.Name, ex);
return Enumerable.Empty<Assembly>();
}
})
.SelectMany(x => x.GetModules()).SelectMany(x => x.GetTypes())
.Where(x => typeof(IWiXCustomUi).IsAssignableFrom(x) && !x.IsAbstract)
.SelectMany(x => {
try {
return new[] {(IWiXCustomUi) Activator.CreateInstance(x)};
} catch (Exception ex) {
this.Log().WarnException("Couldn't create instance: " + x.FullName, ex);
return Enumerable.Empty<IWiXCustomUi>();
}
});

foreach (var extension in extensions) {
extension.RegisterTypes(kernel);
}
}

TinyIoCContainer createDefaultKernel() TinyIoCContainer createDefaultKernel()
{ {
var ret = new TinyIoCContainer(); var ret = new TinyIoCContainer();
Expand Down

0 comments on commit 623905c

Please sign in to comment.