Quantcast
Channel: CommonServiceLocator
Viewing all 118 articles
Browse latest View live

New Post: Update for the NuGet package for .NET 2 support ?

$
0
0
Quite surprised that you released a PCL version and still no support for .net 2, beside the fact that the source code is totally compatible with older framework ?

It takes me 15 minutes to create 2 projects targeting .net 2 & .net 3.5 and adding existing files as link, copy the test projects then update the nuspec to include all versions.

I have submitted a pull request to include it in master, with the minimum changes necessary : https://commonservicelocator.codeplex.com/SourceControl/network/forks/styx31/258764/contribution/6593

New Post: Support for Windows Phone 8.1 app in PCL

$
0
0
The PCL doesn't currently support the new WinPRT based Windows Phone 8.1 app type, so it cannot be referenced. This also affects the new Universal apps.

New Post: Support for Windows Phone 8.1 app in PCL

$
0
0
I confirm. I'm also stucked.
Do you know when the WinRT Phone 8.1 version will be released (or any beta version)?
Thanks.

New Post: Support for Windows Phone 8.1 app in PCL

$
0
0
You can build your own local version that supports WinPRT by downloading or cloning the code and adding Windows Phone 8.1 to the platforms supported by the PCL in projects properties page.

New Post: Support for Windows Phone 8.1 app in PCL

Source code checked in, #d623089dad7c31b5eb01dfbe8de937eb2da250da

$
0
0
Added support for Windows Phone 8.1 and updated version to 1.3

Reviewed: Common Service Locator 1.2 (ago. 09, 2014)

$
0
0
Rated 5 Stars (out of 5) - Is very usefull to abstract any ioc container!

New Post: ServiceLocator.Current - bad implementation

$
0
0
OS: Window 8.1
IDE: VS 2013 Express for Windows
Prism: StoreApps
IoC: Unity
Proj: Universal

Hi,

I'm having a problem getting this to work. Need help on how to initialize the Service, There's no protected override void ConfigureServiceLocator() in MvvmAppBase. Tried this during protected override Task OnInitializeAsync(IActivatedEventArgs args):
ServiceLocator.SetLocatorProvider(() => this._container.Resolve<IServiceLocator>());
and Current is still not set:
    public sealed partial class MainPage : VisualStateAwarePage
    {
        public MainPage()
        {
            this.InitializeComponent();

            NathsarTS.UILogic.Interfaces.IObservableService ObservableService = ServiceLocator.Current.GetInstance<NathsarTS.UILogic.Interfaces.IObservableService>();
        }
    }
...with no success. How do I get this to work in my environment?

Thanks!...

New Post: ServiceLocator.Current - bad implementation

$
0
0
Cancel that! After much searching and testing I finally got it after reading this posts on the Unity Adapter page.
..
private readonly IUnityContainer _container = new UnityContainer();
...
..
.
var locator = new UnityServiceLocator(_container);
ServiceLocator.SetLocatorProvider(() => locator);

Created Unassigned: sn -t: Invalid public key [16055]

$
0
0
```
C:\Users\delirium\Documents\Visual Studio 2013\Projects\test_prism_unity\packages\CommonServiceLocator.1.3\lib\portable-net4+sl5+netcore45+wpa81+wp8>sn -t Microsoft.Practices.ServiceLocation.dll

Microsoft (R) .NET Framework-Dienstprogramm für starke Namen, Version 4.0.30319.33440
Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten.

Der Schlüssel konnte nicht zu Token konvertiert werden -- Ungültiger öffentlicher Schlüssel für Assembly.
```

This may cause assembly redirection to fail - which is a PITA if one uses unity and prism and clicks "update all packages" in nuget package management (which would update CSL to 1.3.0.0, but unity is bound to 1.2.0.0).

Created Unassigned: PLC Version added to the official nuget package [16056]

$
0
0
Can the PCL version of the CommonServiceLocator be added to the official Nuget package please? I need to reference it for cross platform development using Xamarin.

Cheers

New Post: ServiceLocator.Current.GetInstance() is not wokring

$
0
0
Hi

We have an extension method to register the service as shown below

expression.MissingNamedInstanceIs.Conditional(configuration =>
{
    configuration.
      If(context =>
      {
        return (String.IsNullOrEmpty(context.RequestedName) ||
          context.RequestedName.Equals("localhost", StringComparison.OrdinalIgnoreCase) ||
          context.RequestedName.Equals(ServerInfo.HostName, StringComparison.OrdinalIgnoreCase));
      }).
      ThenIt.Is.Type<TService>();

    configuration.TheDefault.Is.ConstructedBy(buildContext =>
    {
      return buildContext.GetInstance<IServiceBuilder>().GetOutOfProcService<TContract>(buildContext);
    });
  });
we are saying return me the out of proc instance only if the key is remote host name. in detail we expected to receive in proc instance for all three calls mentioned below

IStudyService studyService = ServiceLocator.Current.GetInstance<IStudyService>(Stentor.Server.ServerInfo.HostName)

IStudyService studyService2 = ServiceLocator.Current.GetInstance<IStudyService>("localhost");

IStudyService studyService3 = ServiceLocator.Current.GetInstance<IStudyService>()

The first two calls are working as expected but when we go with empty key for third call highlighted one we are getting out of proc instead the in proc

If(context =>
      {
        return (String.IsNullOrEmpty(context.RequestedName) ||
          context.RequestedName.Equals("localhost", StringComparison.OrdinalIgnoreCase) ||
          context.RequestedName.Equals(ServerInfo.HostName, StringComparison.OrdinalIgnoreCase));
      }).
      ThenIt.Is.Type<TService>();
we have condition mentioned like if the requested key empty or localhost or hostanme return ThenIt.Is.Type<TService>();

but for empty key condition it's not working.
(String.IsNullOrEmpty(context.RequestedName) this condition is not wokring and the below code is getting executed

configuration.TheDefault.Is.ConstructedBy(buildContext =>
    {
      return buildContext.GetInstance<IServiceBuilder>().GetOutOfProcService<TContract>(buildContext);
    });
Can you please suggest what's wrong in this code or how the context has to be registered when the empty key needs to be processed

Thanks & regards

Sukumar

Created Unassigned: Found conflicts between different versions of the same dependent assembly that could not be resolved. [16057]

$
0
0
This warning keeps showing up in a .NET 4.5.1 MVC application I'm working on that uses the Unity application block for dependency injection, which references your project.

```
Warning 10 Found conflicts between different versions of the same dependent assembly that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed.
```

After setting build log verbosity to detailed:

```
There was a conflict between "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" and "mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes".
4> "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" was chosen because it was primary and "mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes" was not.
References which depend on "mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes" [].
4> C:\Development\Projects\.....\packages\CommonServiceLocator.1.3\lib\portable-net4+sl5+netcore45+wpa81+wp8\Microsoft.Practices.ServiceLocation.dll
4> Project file item includes which caused reference "C:\Development\Projects\.....\packages\CommonServiceLocator.1.3\lib\portable-net4+sl5+netcore45+wpa81+wp8\Microsoft.Practices.ServiceLocation.dll".
......(removed some application specific lines for brevity)
4> Unity.WebApi
4> Microsoft.Practices.Unity.Mvc
4> Microsoft.Practices.Unity.Configuration, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL
4> Microsoft.Practices.ServiceLocation, Version=1.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL
4> Microsoft.Practices.Unity.RegistrationByConvention
4> Microsoft.Practices.Unity.WebApi
4> Microsoft.Practices.Unity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL

```

Are you planning on releasing a version that targets the newer mscorlib? Is this related to issue [12616](https://commonservicelocator.codeplex.com/workitem/12616)?

New Post: StructureMap.IContext.RequestedName?

$
0
0
Hi

1)IStudyService studyService3 = ServiceLocator.Current.GetInstance<IStudyService>();
What would be the StructureMap.IContext.RequestedName in the above call , when we go with empty key?
Will it be null or wmpty?

Key Note:
IStudyService studyService2 = ServiceLocator.Current.GetInstance<IStudyService>"localhost");
In the above condition StructureMap.IContext.RequestedName will be "localhost" which was given as key.

But in the first condition what would be the RequestedName?

The question is raised due to this below situation

If(context =>
      {
        return (String.IsNullOrEmpty(context.RequestedName) ||
          context.RequestedName.Equals("localhost", StringComparison.OrdinalIgnoreCase) ||
      }).
when we are checking the context.RequestedName with null or empty the above check fails as i mentioned earlier.

Thanks in advance

Regards
Sukumar

Commented Issue: Null reference handling [12807]

$
0
0
While testing the ServiceLocator.Current.GetInstance method, I passed a null to verify the libraries design correctness (we use Microsoft Basic Design Guidelines Rules, and try to test our external libraries for them).
 
I ran into this exception when calling:
 
ServiceLocator.Current.GetInstance(null);
 
Stack Trace:
 
at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.FormatActivationExceptionMessage(Exception actualException, Type serviceType, String key) in c:\Home\Chris\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs:line 149
at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) in c:\Home\Chris\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs:line 53
at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType) in c:\Home\Chris\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs:line 34
at DiscoveryPrototype.ClientApp.Program.Main(String[] args) in D:\Projects\DiscoveryPrototype\DiscoveryPrototype.ClientApp\Program.cs:line 19
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
 
 
The ServiceLocatorImplBase should really have null checks in all methods for all used parameters. Although it is an edge case, you could ask for an instance of an object passing in the type that came from the return of a method that DOES return null, and then the exception is not caught at the proper place.
Comments: And now I'm going insane for that problem!

New Comment on "Autofac Adapter"

$
0
0
This is no longer accurate. The correct adapter is https://www.nuget.org/packages/Autofac.Extras.CommonServiceLocator/

Created Unassigned: Update Autofac links [16058]

$
0
0
They are no longer in google code but in github. Since the Autofac integration link takes people directly to the downloads page they will not even see the message about this move.

Created Unassigned: GetInstance(Type type) breaks UserControls in VS2013 and 2015 designer [16059]

$
0
0
It's hard to know if this is a Visual Studio bug or a CommonServiceLocator bug but I decided to post here first.

I'm having an issue where if I call ```ServiceLocator.Current.GetInstance(type)``` anywhere in my project, it causes UserControls throughout my project to stop instantiating within other controls at design-time in Visual Studio (tried 2013 and 2015). These controls work fine at run-time however. The line of code doesn't even have to be connected to any other code in anyway. If it's anywhere in the project, it causes problems. It does not happen with other function calls such as ```ServiceLocator.Current.GetInstance<AnyType>()```

It is reproducible by creating a simple WpfApplication with the following 3 classes. The first build will succeed, and the designer will show fine. If you rebuild, however, it throws the error and the designer stops instantiating the UserControls within other controls. Because of this behavior, it seems like a Visual Studio bug, but I'm not sure.

When uncommented, the ```#GetInstance(Type type)``` function of ServiceLocator causes an Error in the error list ```Cannot locate resource 'controls/test.xaml``` and the designer shows an error ```Cannot create an instance of "Test"``` where the Test UserControl should be. When commented, there are no errors.

Test xaml class.
```
<UserControl x:Class="XamlTest.Controls.Test"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d">
<Grid>
<Label Content="Test"/>
</Grid>
</UserControl>
```
MyView xaml class. (uses Test)
```
<UserControl x:Class="XamlTest.Views.MyView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mycontrols="clr-namespace:XamlTest.Controls"
mc:Ignorable="d">
<Grid>
<mycontrols:Test/>
</Grid>
</UserControl>
```
A class unrelated to the UserControls that uses ServiceLocator.Current.GetInstance(type);.

using Microsoft.Practices.ServiceLocation;
```
namespace XamlTest.SomeClasses
{
class SomeClass
{
public void SomeFunction()
{
// Causes Test xaml class to not instantiate at design time within MyView.
// Does not matter what parameters you give the function.
// Notice this class isn't even associated with any other class,
// and is never called, but it still causes problems.
ServiceLocator.Current.GetInstance(null);
}

}
}
```

You can also find a ready-made example project of this issue on github at [https://github.com/bzuillsmith/xamltest/tree/master/XamlTest](https://github.com/bzuillsmith/xamltest/tree/master/XamlTest)

New Post: Core .NET?

$
0
0
Just curious if this project has any plans of recompiling itself so that it is compatible with Core .NET5?

New Post: Resources will make Windows Store think that my app supports English

Viewing all 118 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>