Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dependency injection using SimpleInjector #16

Merged
merged 5 commits into from Aug 9, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Create WordTutorApplicationStateFactory

  • Loading branch information...
theunrepentantgeek committed Jul 21, 2019
commit b30fa355a4a7f644cc1e9ecbd70439603aa08537
@@ -1,4 +1,4 @@
using SimpleInjector;
using SimpleInjector;
using System;
using System.Reflection;
using System.Windows;
@@ -8,17 +8,17 @@
using WordTutor.Core.Redux;
using WordTutor.Desktop;

static class Program
static partial class Program
{
[STAThread]
static void Main()
{
var application = CreateApplicationModel();
var store = CreateStore(application);
var container = CreateContainer(store);
var container = CreateContainer();

var app = new App();

var store = container.GetInstance<ReduxStore<WordTutorApplication>>();

var model = new VocabularyBrowserViewModel(store);
var view = new VocabularyBrowserView
{
@@ -31,60 +31,19 @@ static void Main()
app.Run(mainWindow);
}

private static IReduxStore<WordTutorApplication> CreateStore(WordTutorApplication application)
{
var reducer = new CompositeReduxReducer<WordTutorApplication>(
new IReduxReducer<WordTutorApplication>[]
{
new AddVocabularyWordScreenReducer(),
new VocabularyBrowserScreenReducer()
});

var store = new ReduxStore<WordTutorApplication>(reducer, application);
return new LoggingReduxStore<WordTutorApplication>(store);
}

private static WordTutorApplication CreateApplicationModel()
{
var alpha = new VocabularyWord("alpha")
.WithPhrase("The alpha dog")
.WithPronunciation("alfa");

var beta = new VocabularyWord("beta")
.WithPhrase("A beta release")
.WithPronunciation("beta");

var gamma = new VocabularyWord("gamma")
.WithPhrase("Gamma radiation")
.WithPronunciation("gamma");

var delta = new VocabularyWord("delta")
.WithPhrase("Change is often called delta.")
.WithPronunciation("delta");

var vocabulary = VocabularySet.Empty
.Add(alpha)
.Add(beta)
.Add(gamma)
.Add(delta);

var screen = new VocabularyBrowserScreen()
.WithSelection(gamma);

var application = new WordTutorApplication(screen)
.WithVocabularySet(vocabulary);

return application;
}

private static Container CreateContainer()
{
var container = new Container();
var coreAssembly = typeof(WordTutorApplication).Assembly;
var desktopAssembly = Assembly.GetExecutingAssembly();

// Register Redux
container.RegisterSingleton<
IReduxStore<WordTutorApplication>,
ReduxStore<WordTutorApplication>>();
container.RegisterSingleton<
IReduxStateFactory<WordTutorApplication>,
WordTutorApplicationStateFactory>();

container.Verify();

@@ -0,0 +1,41 @@
using WordTutor.Core;
using WordTutor.Core.Redux;

namespace WordTutor.Desktop
{
public class WordTutorApplicationStateFactory : IReduxStateFactory<WordTutorApplication>
{
public WordTutorApplication Create()
{
var alpha = new VocabularyWord("alpha")
.WithPhrase("The alpha dog")
.WithPronunciation("alfa");

var beta = new VocabularyWord("beta")
.WithPhrase("A beta release")
.WithPronunciation("beta");

var gamma = new VocabularyWord("gamma")
.WithPhrase("Gamma radiation")
.WithPronunciation("gamma");

var delta = new VocabularyWord("delta")
.WithPhrase("Change is often called delta.")
.WithPronunciation("delta");

var vocabulary = VocabularySet.Empty
.Add(alpha)
.Add(beta)
.Add(gamma)
.Add(delta);

var screen = new VocabularyBrowserScreen()
.WithSelection(gamma);

var application = new WordTutorApplication(screen)
.WithVocabularySet(vocabulary);

return application;
}
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.