Skip to content

Commit 555b7d0

Browse files
committed
update
Refactor factories
1 parent 8be3301 commit 555b7d0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+149
-83
lines changed

LICENSE

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
* PureMVC MultiCore Framework for C# - Copyright © 2017 [Saad Shams](http://saad.io)
2-
* PureMVC - Copyright © 2017 [Futurescale, Inc](http://futurescale.com).
1+
* PureMVC MultiCore Framework for C# - Copyright © 2020 [Saad Shams](http://saad.io)
2+
* PureMVC - Copyright © 2020 [Futurescale, Inc](http://futurescale.com).
33
* All rights reserved.
44

55
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

PureMVC/Core/Controller.cs

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// PureMVC C# Multicore
33
//
4-
// Copyright(c) 2017 Saad Shams <[email protected]>
4+
// Copyright(c) 2020 Saad Shams <[email protected]>
55
// Your reuse is governed by the Creative Commons Attribution 3.0 License
66
//
77

@@ -93,11 +93,11 @@ protected virtual void InitializeController()
9393
/// <c>Controller</c> Multiton Factory method.
9494
/// </summary>
9595
/// <param name="key">Key of controller</param>
96-
/// <param name="func">the <c>FuncDelegate</c> of the <c>IController</c></param>
96+
/// <param name="factory">the <c>FuncDelegate</c> of the <c>IController</c></param>
9797
/// <returns>the Multiton instance of <c>Controller</c></returns>
98-
public static IController GetInstance(string key, Func<string, IController> func)
98+
public static IController GetInstance(string key, Func<string, IController> factory)
9999
{
100-
return InstanceMap.GetOrAdd(key, new Lazy<IController>(() => func(key))).Value;
100+
return InstanceMap.GetOrAdd(key, new Lazy<IController>(factory(key))).Value;
101101
}
102102

103103
/// <summary>
@@ -107,9 +107,9 @@ public static IController GetInstance(string key, Func<string, IController> func
107107
/// <param name="notification">note an <c>INotification</c></param>
108108
public virtual void ExecuteCommand(INotification notification)
109109
{
110-
if (commandMap.TryGetValue(notification.Name, out var commandFunc))
110+
if (commandMap.TryGetValue(notification.Name, out var factory))
111111
{
112-
var commandInstance = commandFunc();
112+
var commandInstance = factory();
113113
commandInstance.InitializeNotifier(multitonKey);
114114
commandInstance.Execute(notification);
115115
}
@@ -131,14 +131,14 @@ public virtual void ExecuteCommand(INotification notification)
131131
/// </para>
132132
/// </remarks>
133133
/// <param name="notificationName">the name of the <c>INotification</c></param>
134-
/// <param name="commandFunc">the <c>Func Delegate</c> of the <c>ICommand</c></param>
135-
public virtual void RegisterCommand(string notificationName, Func<ICommand> commandFunc)
134+
/// <param name="factory">the <c>Func Delegate</c> of the <c>ICommand</c></param>
135+
public virtual void RegisterCommand(string notificationName, Func<ICommand> factory)
136136
{
137137
if (commandMap.TryGetValue(notificationName, out _) == false)
138138
{
139139
view.RegisterObserver(notificationName, new Observer(ExecuteCommand, this));
140140
}
141-
commandMap[notificationName] = commandFunc;
141+
commandMap[notificationName] = factory;
142142
}
143143

144144
/// <summary>

PureMVC/Core/Model.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// PureMVC C# Multicore
33
//
4-
// Copyright(c) 2017 Saad Shams <[email protected]>
4+
// Copyright(c) 2020 Saad Shams <[email protected]>
55
// Your reuse is governed by the Creative Commons Attribution 3.0 License
66
//
77

@@ -71,11 +71,11 @@ protected virtual void InitializeModel()
7171
/// <c>Model</c> Multiton Factory method.
7272
/// </summary>
7373
/// <param name="key">Key of model</param>
74-
/// <param name="func">the <c>FuncDelegate</c> of the <c>IModel</c></param>
74+
/// <param name="factory">the <c>FuncDelegate</c> of the <c>IModel</c></param>
7575
/// <returns>the instance for this Multiton key </returns>
76-
public static IModel GetInstance(string key, Func<string, IModel> func)
76+
public static IModel GetInstance(string key, Func<string, IModel> factory)
7777
{
78-
return InstanceMap.GetOrAdd(key, new Lazy<IModel>(() => func(key))).Value;
78+
return InstanceMap.GetOrAdd(key, new Lazy<IModel>(factory(key))).Value;
7979
}
8080

8181
/// <summary>

PureMVC/Core/View.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// PureMVC C# Multicore
33
//
4-
// Copyright(c) 2017 Saad Shams <[email protected]>
4+
// Copyright(c) 2020 Saad Shams <[email protected]>
55
// Your reuse is governed by the Creative Commons Attribution 3.0 License
66
//
77

@@ -72,11 +72,11 @@ protected virtual void InitializeView()
7272
/// <c>View</c> Multiton Factory method.
7373
/// </summary>
7474
/// <param name="key">Key of view</param>
75-
/// <param name="func">the <c>FuncDelegate</c> of the <c>IView</c></param>
75+
/// <param name="factory">the <c>FuncDelegate</c> of the <c>IView</c></param>
7676
/// <returns>the instance for this Multiton key </returns>
77-
public static IView GetInstance(string key, Func<string, IView> func)
77+
public static IView GetInstance(string key, Func<string, IView> factory)
7878
{
79-
return InstanceMap.GetOrAdd(key, new Lazy<IView>(() => func(key))).Value;
79+
return InstanceMap.GetOrAdd(key, new Lazy<IView>(factory(key))).Value;
8080
}
8181

8282
/// <summary>

PureMVC/Interfaces/ICommand.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// PureMVC C# Multicore
33
//
4-
// Copyright(c) 2017 Saad Shams <[email protected]>
4+
// Copyright(c) 2020 Saad Shams <[email protected]>
55
// Your reuse is governed by the Creative Commons Attribution 3.0 License
66
//
77

PureMVC/Interfaces/IController.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// PureMVC C# Multicore
33
//
4-
// Copyright(c) 2017 Saad Shams <[email protected]>
4+
// Copyright(c) 2020 Saad Shams <[email protected]>
55
// Your reuse is governed by the Creative Commons Attribution 3.0 License
66
//
77

@@ -43,8 +43,8 @@ public interface IController
4343
/// for a particular <c>INotification</c>.
4444
/// </summary>
4545
/// <param name="notificationName">the name of the <c>INotification</c></param>
46-
/// <param name="commandFunc">the FuncDelegate of the <c>ICommand</c></param>
47-
void RegisterCommand(string notificationName, Func<ICommand> commandFunc);
46+
/// <param name="factory">the FuncDelegate of the <c>ICommand</c></param>
47+
void RegisterCommand(string notificationName, Func<ICommand> factory);
4848

4949
/// <summary>
5050
/// Execute the <c>ICommand</c> previously registered as the

PureMVC/Interfaces/IFacade.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// PureMVC C# Multicore
33
//
4-
// Copyright(c) 2017 Saad Shams <[email protected]>
4+
// Copyright(c) 2020 Saad Shams <[email protected]>
55
// Your reuse is governed by the Creative Commons Attribution 3.0 License
66
//
77

PureMVC/Interfaces/IMediator.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// PureMVC C# Multicore
33
//
4-
// Copyright(c) 2017 Saad Shams <[email protected]>
4+
// Copyright(c) 2020 Saad Shams <[email protected]>
55
// Your reuse is governed by the Creative Commons Attribution 3.0 License
66
//
77

PureMVC/Interfaces/IModel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// PureMVC C# Multicore
33
//
4-
// Copyright(c) 2017 Saad Shams <[email protected]>
4+
// Copyright(c) 2020 Saad Shams <[email protected]>
55
// Your reuse is governed by the Creative Commons Attribution 3.0 License
66
//
77

PureMVC/Interfaces/INotification.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// PureMVC C# Multicore
33
//
4-
// Copyright(c) 2017 Saad Shams <[email protected]>
4+
// Copyright(c) 2020 Saad Shams <[email protected]>
55
// Your reuse is governed by the Creative Commons Attribution 3.0 License
66
//
77

PureMVC/Interfaces/INotifier.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// PureMVC C# Multicore
33
//
4-
// Copyright(c) 2017 Saad Shams <[email protected]>
4+
// Copyright(c) 2020 Saad Shams <[email protected]>
55
// Your reuse is governed by the Creative Commons Attribution 3.0 License
66
//
77

PureMVC/Interfaces/IObserver.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// PureMVC C# Multicore
33
//
4-
// Copyright(c) 2017 Saad Shams <[email protected]>
4+
// Copyright(c) 2020 Saad Shams <[email protected]>
55
// Your reuse is governed by the Creative Commons Attribution 3.0 License
66
//
77

PureMVC/Interfaces/IProxy.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// PureMVC C# Multicore
33
//
4-
// Copyright(c) 2017 Saad Shams <[email protected]>
4+
// Copyright(c) 2020 Saad Shams <[email protected]>
55
// Your reuse is governed by the Creative Commons Attribution 3.0 License
66
//
77

PureMVC/Interfaces/IView.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// PureMVC C# Multicore
33
//
4-
// Copyright(c) 2017 Saad Shams <[email protected]>
4+
// Copyright(c) 2020 Saad Shams <[email protected]>
55
// Your reuse is governed by the Creative Commons Attribution 3.0 License
66
//
77

PureMVC/Patterns/Command/MacroCommand.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// PureMVC C# Multicore
33
//
4-
// Copyright(c) 2017 Saad Shams <[email protected]>
4+
// Copyright(c) 2020 Saad Shams <[email protected]>
55
// Your reuse is governed by the Creative Commons Attribution 3.0 License
66
//
77

@@ -98,10 +98,10 @@ protected virtual void InitializeMacroCommand()
9898
/// order.
9999
/// </para>
100100
/// </remarks>
101-
/// <param name="commandFunc">a reference to the <c>FuncDelegate</c> of the <c>ICommand</c>.</param>
102-
protected void AddSubCommand(Func<ICommand> commandFunc)
101+
/// <param name="factory">a reference to the <c>FuncDelegate</c> of the <c>ICommand</c>.</param>
102+
protected void AddSubCommand(Func<ICommand> factory)
103103
{
104-
subcommands.Add(commandFunc);
104+
subcommands.Add(factory);
105105
}
106106

107107
/// <summary>
@@ -118,8 +118,8 @@ public virtual void Execute(INotification notification)
118118
{
119119
while(subcommands.Count > 0)
120120
{
121-
var commandFunc = subcommands[0];
122-
var commandInstance = commandFunc();
121+
var factory = subcommands[0];
122+
var commandInstance = factory();
123123
commandInstance.InitializeNotifier(MultitonKey);
124124
commandInstance.Execute(notification);
125125
subcommands.RemoveAt(0);

PureMVC/Patterns/Command/SimpleCommand.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// PureMVC C# Multicore
33
//
4-
// Copyright(c) 2017 Saad Shams <[email protected]>
4+
// Copyright(c) 2020 Saad Shams <[email protected]>
55
// Your reuse is governed by the Creative Commons Attribution 3.0 License
66
//
77

@@ -22,7 +22,7 @@ namespace PureMVC.Patterns.Command
2222
/// <seealso cref="PureMVC.Core.Controller"/>
2323
/// <seealso cref="PureMVC.Patterns.Observer.Notification"/>
2424
/// <seealso cref="PureMVC.Patterns.Command.MacroCommand"/>
25-
public class SimpleCommand : Notifier, ICommand, INotifier
25+
public class SimpleCommand : Notifier, ICommand
2626
{
2727
/// <summary>
2828
/// Fulfill the use-case initiated by the given <c>INotification</c>.

PureMVC/Patterns/Facade/Facade.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// PureMVC C# Multicore
33
//
4-
// Copyright(c) 2017 Saad Shams <[email protected]>
4+
// Copyright(c) 2020 Saad Shams <[email protected]>
55
// Your reuse is governed by the Creative Commons Attribution 3.0 License
66
//
77

@@ -62,11 +62,11 @@ protected virtual void InitializeFacade()
6262
/// Facade Multiton Factory method
6363
/// </summary>
6464
/// <param name="key">Key of facade</param>
65-
/// <param name="func">the <c>FuncDelegate</c> of the <c>IFacade</c></param>
65+
/// <param name="factory">the <c>FuncDelegate</c> of the <c>IFacade</c></param>
6666
/// <returns>the Multiton instance of the Facade</returns>
67-
public static IFacade GetInstance(string key, Func<string, IFacade> func)
67+
public static IFacade GetInstance(string key, Func<string, IFacade> factory)
6868
{
69-
return InstanceMap.GetOrAdd(key, new Lazy<IFacade>(() => func(key))).Value;
69+
return InstanceMap.GetOrAdd(key, new Lazy<IFacade>(factory(key))).Value;
7070
}
7171

7272
/// <summary>

PureMVC/Patterns/Mediator/Mediator.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// PureMVC C# Multicore
33
//
4-
// Copyright(c) 2017 Saad Shams <[email protected]>
4+
// Copyright(c) 2020 Saad Shams <[email protected]>
55
// Your reuse is governed by the Creative Commons Attribution 3.0 License
66
//
77

PureMVC/Patterns/Observer/Notification.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// PureMVC C# Multicore
33
//
4-
// Copyright(c) 2017 Saad Shams <[email protected]>
4+
// Copyright(c) 2020 Saad Shams <[email protected]>
55
// Your reuse is governed by the Creative Commons Attribution 3.0 License
66
//
77

PureMVC/Patterns/Observer/Notifier.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// PureMVC C# Multicore
33
//
4-
// Copyright(c) 2017 Saad Shams <[email protected]>
4+
// Copyright(c) 2020 Saad Shams <[email protected]>
55
// Your reuse is governed by the Creative Commons Attribution 3.0 License
66
//
77

PureMVC/Patterns/Observer/Observer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// PureMVC C# Multicore
33
//
4-
// Copyright(c) 2017 Saad Shams <[email protected]>
4+
// Copyright(c) 2020 Saad Shams <[email protected]>
55
// Your reuse is governed by the Creative Commons Attribution 3.0 License
66
//
77

PureMVC/Patterns/Proxy/Proxy.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// PureMVC C# Multicore
33
//
4-
// Copyright(c) 2017 Saad Shams <[email protected]>
4+
// Copyright(c) 2020 Saad Shams <[email protected]>
55
// Your reuse is governed by the Creative Commons Attribution 3.0 License
66
//
77

PureMVCTests/Core/ControllerTest.cs

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// PureMVC C# Multicore
33
//
4-
// Copyright(c) 2017 Saad Shams <[email protected]>
4+
// Copyright(c) 2020 Saad Shams <[email protected]>
55
// Your reuse is governed by the Creative Commons Attribution 3.0 License
66
//
77

@@ -207,5 +207,21 @@ public void TestReRegisterAndExecuteCommand()
207207
// if the command is executed twice the value will be 48
208208
Assert.IsTrue(vo.result == 48, "Expecting vo.result == 48");
209209
}
210+
211+
/// <summary>
212+
/// Tests the multiton instances
213+
/// </summary>
214+
[TestMethod]
215+
public void TestMultitons()
216+
{
217+
var temp1 = Controller.GetInstance("A", k => new Controller(k));
218+
var temp2 = Controller.GetInstance("A", k => new Controller(k));
219+
220+
Assert.IsTrue(temp1 == temp2);
221+
222+
temp2 = Controller.GetInstance("B", k => new Controller(k));
223+
224+
Assert.IsFalse(temp1 == temp2);
225+
}
210226
}
211227
}

PureMVCTests/Core/ControllerTestCommand.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// PureMVC C# Multicore
33
//
4-
// Copyright(c) 2017 Saad Shams <[email protected]>
4+
// Copyright(c) 2020 Saad Shams <[email protected]>
55
// Your reuse is governed by the Creative Commons Attribution 3.0 License
66
//
77

PureMVCTests/Core/ControllerTestCommand2.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// PureMVC C# Multicore
33
//
4-
// Copyright(c) 2017 Saad Shams <[email protected]>
4+
// Copyright(c) 2020 Saad Shams <[email protected]>
55
// Your reuse is governed by the Creative Commons Attribution 3.0 License
66
//
77

PureMVCTests/Core/ControllerTestVO.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// PureMVC C# Multicore
33
//
4-
// Copyright(c) 2017 Saad Shams <[email protected]>
4+
// Copyright(c) 2020 Saad Shams <[email protected]>
55
// Your reuse is governed by the Creative Commons Attribution 3.0 License
66
//
77

0 commit comments

Comments
 (0)