Prism4: Creating catalog from xaml CreateFromXaml doesn't compile - silverlight-4.0

I'm developing with Silverlight 4 and Prism 4.
I'm also using Unity as my injection container.
I'm trying to create the module catalog from xaml, but I get this error "IModuleCatalog does not contain a definition of CreateFromXaml...".
My code snippet is:
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Practices.Prism.UnityExtensions;
using Microsoft.Practices.ServiceLocation;
using Microsoft.Practices.Prism.Modularity;
using Microsoft.Practices.Prism.MefExtensions;
namespace MyModularityProject {
public class MyBootStrapper : UnityBootstrapper {
protected override DependencyObject CreateShell() {
return ServiceLocator.Current.GetInstance<Shell>();
}
protected override void InitializeShell() {
base.InitializeShell();
Application.Current.RootVisual = (UIElement)Shell;
}
protected override IModuleCatalog CreateModuleCatalog() {
// This is the isntruction that doesn't compile
return ModuleCatalog.CreateFromXaml(new
Uri("/MyProject.Silverlight;component/ModulesCatalog.xaml",
UriKind.Relative));
}
}
}
What could I be missing here?

The reason that you need to add the full path to the ModuleCatalog type is that there is a ModuleCatalog property within the Bootstrapper base class that UnityBootstrapper inherits. If you don't qualify the name, you are essentially calling an accessor on a property which returns IModuleCatalog. The interface definition does not include this function.

Related

OpenIso8583.Net Adding a bit to the template

The library was moved some years ago and the link I found for a wiki is stale.
I would like to add bit 127 to the Iso8583 class. I am using the below code but the program dies in the Pack() method, called from ToMsg(). I don't know what value to put in the length field. The field is a LLLVAR with a max length of 5, so is the length 5, or 8, or 999? All three values throw an exception in Pack().
What do I need to add to get bit 127 working?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using OpenIso8583Net;
using OpenIso8583Net.FieldValidator;
using OpenIso8583Net.Formatter;
using OpenIso8583Net.LengthFormatters;
namespace MyLink
{
public class MyIso8583 : Iso8583
{
public new class Bit : Iso8583.Bit
{
public const int _127_DISCOVER_VERSION = 127;
}
// First you need to customise the template
// The message
private static readonly Template template;
static MyIso8583()
{
// Get the default template for the Iso8583 class
template = GetDefaultIso8583Template();
// change template to add bit 127 LLLVAR(5)
template.Add(Bit._127_DISCOVER_VERSION, FieldDescriptor.AsciiVar(3, 5, FieldValidators.AlphaNumericSpecial));
}
// override the base class using the template
public MyIso8583() : base(template)
{
}
protected override IField CreateField(int field)
{
return base.CreateField(field);
}
}
}
EDIT 3/24/20: I added an override to Bit and CreateField. I want the new bit 127 to act like a default LLLVAR of length 5.
This code works. It may not actually be necessary to add the CreateField override.

Property Injection in Microsoft.Extensions.DependencyInjection

I am relatively new to working with DI containers and have hit a bit of a roadblock.
SimpleInjector has a method with the following signature:
Container.RegisterInitializer<TService>(Action<TService>)
In our code base we do use it like this:
// this is a property injection of the abstract file system
container.RegisterInitializer<IFileSystemInjection>(
fs => fs.FileSystem = new FileSystem());
I am wondering how I would achieve the same using the IServiceCollection parameter in the ConfigureServices method in the Startup.cs class. So far I have been able to register all my types using the services.AddTransient(); but I am not sure how what the equivalent simpleinjector.RegisterInitializer is within the IServiceCollection.
You'd use the factory overload(s) of AddSingleton, AddScoped, and AddTransient. I'm not sure what scope IFileSystemInjection should be in, but it sounds like something that could be a singleton. If not, change the method you call appropriately:
service.AddSingleton<IFileSystemInjection>(p =>
{
var fs = new FileSystemInjection();
fs.FileSystem = new FileSystem();
});
In short, if you provide a factory, then you're responsible for the entire object initialization, hence the new FileSystemInjection(), which I'm subbing as the actual implementation of IFileSystemInjection your using.
If that implementation has dependencies that need to be injected in order to create it, you can pull those from p, which is an instance of IServiceProvider:
var myDep = p.GetRequiredService<MyDep>();
var fs = new FileSystemImplementation(myDep);
You can use this nuget package, that extends standard Microsoft Dependency Injection and adds property injection:
https://www.nuget.org/packages/DJMJ.Extensions.DependencyInjection.Property/1.1.0
Mark property for injection
using Microsoft.Extensions.DependencyInjection;
public class FooService
{
[Inject]
public IBooService BooService { get; set; }
public void Foo()
{
// just start using injected property
BooService...
}
}
Add services scan method in ConfigureServices
using Microsoft.Extensions.DependencyInjection;
...
host.ConfigureServices((services)=>
{
services.AddTransient<IBooService, BooService>();
services.AddTransient<IFooService, FooService>();
// scan method
services.AddPropertyInjectedServices();
});
If you using this extension in asp net and want add property injection support in controllers too, you should add in ConfigureServices this statement:
services.AddControllers().AddControllersAsServices()

Symfony - Create Service object with parameters

I created a new service in my symfony application:
namespace AppBundle\Service;
class CustomService {
public function __construct($username, $password) {
// stuff
}
public function getItems() {
}
}
and configured in config.yml:
services:
custom_service:
class: AppBundle\Service\CustomService
My question is, how to create an object from this service with multiple arguments?
Like:
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
class CustomController extends Controller {
public function listAction() {
$custom_service = $this->get('custom_service'); //how to pass multiple arguments here?
// Next i would use my custom service, like:
$items = $custom_service->getItems();
}
}
Anybody knows how to solve this issue?
Thanks and Greetings!
Basically you don't. The container supports injecting dependencies. Doing what you propose kind of defeats the purpose of using a dependency injection container.
One work around is to add an init method to your object.
$custom_service = $this->get('custom_service')->init($additional_arguments);

Can you apply aspects in PostSharp without using attributes?

I know with Castle Windsor, you can register aspects (when using method interception in Windsor as AOP) using code instead of applying attributes to classes. Is the same possible in Postsharp? It's a preference things, but prefer to have aspects matched to interfaces/objects in one place, as opposed to attributes all over.
Update:
Curious if I can assign aspects to interfaces/objects similiar to this:
container.Register(
Component
.For<IService>()
.ImplementedBy<Service>()
.Interceptors(InterceptorReference.ForType<LoggingAspect>()).Anywhere
);
If you could do this, you would have the option of NOT having to place attributes on assemblies/class/methods to apply aspects. I can then have one code file/class that contains which aspects are applied to which class/methods/etc.
Yes. You can either use multicasting (http://www.sharpcrafters.com/blog/post/Day-2-Applying-Aspects-with-Multicasting-Part-1.aspx , http://www.sharpcrafters.com/blog/post/Day-3-Applying-Aspects-with-Multicasting-Part-2.aspx) or you can use aspect providers (http://www.sharpcrafters.com/blog/post/PostSharp-Principals-Day-12-e28093-Aspect-Providers-e28093-Part-1.aspx , http://www.sharpcrafters.com/blog/post/PostSharp-Principals-Day-13-e28093-Aspect-Providers-e28093-Part-2.aspx).
Example:
using System;
using PostSharp.Aspects;
using PostSharp.Extensibility;
[assembly: PostSharpInterfaceTest.MyAspect(AttributeTargetTypes = "PostSharpInterfaceTest.Interface1", AttributeInheritance = MulticastInheritance.Multicast)]
namespace PostSharpInterfaceTest
{
class Program
{
static void Main(string[] args)
{
Example e = new Example();
Example2 e2 = new Example2();
e.DoSomething();
e2.DoSomething();
Console.ReadKey();
}
}
class Example : Interface1
{
public void DoSomething()
{
Console.WriteLine("Doing something");
}
}
class Example2 : Interface1
{
public void DoSomething()
{
Console.WriteLine("Doing something else");
}
}
interface Interface1
{
void DoSomething();
}
[Serializable]
class MyAspect : OnMethodBoundaryAspect
{
public override void OnEntry(MethodExecutionArgs args)
{
Console.WriteLine("Entered " + args.Method.Name);
}
}
}
I recommend that if you have complex requirements for determining which types get certain aspects that you consider creating an aspect provider instead.
Have a look at LOOM.NET, there you have a post compiler and a runtime weaver. With the later one you are able to archive exactly what you want.
It should be possible to use the PostSharp XML configuration. The XML configuration is the unification of the Plug-in and Project models in the project loader.
Description of .psproj could be found at http://www.sharpcrafters.com/blog/post/Configuring-PostSharp-Diagnostics-Toolkits.aspx.
Note, that I've only seen examples how PostSharp Toolkits use this XML configuration.
But it should work for custom aspects the same way.
Warning: I've noticed that installation of a PostSharp Toolkit from Nuget overwrites existing psproj file. So do not forget to back up it.

Provide C#'s namespace from IronPython

I want to write Tomboy add-on using IronPython and I'm stuck and very beginning -- I need to provide C#'s namespace.
I mean, here's howto in writing Tomboy add-on's http://live.gnome.org/Tomboy/HowToCreateAddins
Let's start with creating the plugin
file called InsertDateTime.cs with the
following content:
using Tomboy;
namespace Tomboy.InsertDateTime
{
public class InsertDateTimeAddin : NoteAddin
{
public override void Initialize ()
{
}
public override void Shutdown ()
{
}
public override void OnNoteOpened ()
{
}
}
}
Can I do that with IronPython? Thank you.
From Python you can import the clr module and then call clr.AddReference('AssemblyName') where assembly name is a partial or full assembly name - maybe in your case it's Tomboy, it's whatever you'd compile against with C#. Then you can do "import Tomboy" or "from Tomboy import NoteAddin".
If you're hosting IronPython via the hosting APIs you can instead do scriptRuntime.LoadAssembly(typeof(NoetAddin).Assembly); so that you don't have to do it in Python. That can be particularly useful to avoid various loader context issues depending on how the assembly gets loaded.