Alternative to add a ServiceLocator instead of App.cs - xamarin.forms

In my Xamarin Forms project i have following architecture:
A portable project which handle common gui stuff and is inherited by each mobile platform project.
Portable Common project which handles all logic stuff and is inherited by each mobile platform project.
I'm planning to use MVVM Light libraries and SimpleIOC.
Now to the question, in my portable project with common gui stuff i can add a servicelocator (to handle all the viewmodels) to App.cs so that's fine.
But how can i add it to the common project, to handle services and other logic stuff ?

You won't need an instance of ServiceLocator in every library.
Let's say you got a class LibraryDependency in your library and register it to a ServiceLocator in the library, your main ServiceLocator can't resolve the dependency if you add it to a ViewModel contructor.
Just register all desired dependencies to the SimpleIoC container in your (executable) main project.

Related

How can I use an interface in a main controller of an ASP.NET MVC project?

I am working on ASP.NET MVC project where I have one solution dotnetmvc which contains two projects:
dotnetmvc (main project)
Service (contains an interface for it).
My problem is that when I am trying to use an interface from the Service project within a controller of the main project then I am not getting a reference to the interface.
Please refer to the below screenshots:
Screenshot 1
Screenshot 2
What am I missing?
I know of 2 reasons why this would happen:
your interface is not public. make sure you add public.
public interface IUser
{
.......
}
the project dotnetmvc is on a lower dotnet version as the Service project
Right click on each project, select properties and make sure dotnet version is the same on both projects

Publish Web API controllers in separate files

I have a problem with publishing Web API in Visual Studio.
In VS, when I publish the Web API, it is published as dll's, and when we have several controllers it is going to aggregate those into one dll.
But I have project that can have different controllers, like:
Android.cs
CoWorker.cs
TelegramBot.cs
and when I publish the project, I would like to publish the controllers in separated DLL's, because I should have update the controllers continuously and when I have an error in a specific controller, I can't publish another.
Please help!
What you are looking for will not happen on its own. If you want a plug and play like architecture where you can just publish only a module without re-publishing the whole solution.
To achieve this you need to move your controller(s)/module as a separate project (separate library). One of the useful configuration feature of ASP.NET Web API is that it allows you to define about the assemblies into which it will look to discover your controller types.
This is very useful if you have external assemblies and are not part of the Web API project.
You can implement interface System.Web.Http.Dispatcher.IAssembliesResolver GetAssemblies() or even can extend the DefaultAssembliesResolver as following.
public class CustomAssembliesResolver : DefaultAssembliesResolver
{
public override ICollection<Assembly> GetAssemblies()
{
//Your implementation here
}
}
You can find more details on this on following link.
MSDN
Sample
I think what you're looking for is a MICRO-SERVICE architecture ...
https://learn.microsoft.com/en-us/dotnet/standard/microservices-architecture/multi-container-microservice-net-applications/data-driven-crud-microservice
https://github.com/dotnet-architecture/eShopOnContainers
you can use .NET full framework
or the new .NET Core (it depends on what you have to do)

how to create a signalR hub proxy in javascript, having hubs in class library?

currently, am working on chat application using signalR and agsxmpp library, I have seen many examples how to create a proxy of hub in javascript. however, my architecture is differ from these examples.
I have class library and a web project(web forms)
Hubs are written in class library, and java script exists in web project, I want to create proxy of hub(written in class library) in java script I have tried a lot. but couldn't find a solution.
I have read owin(startup.cs) but still not a clear picture, where should I keep my owin class, in web project or class library?
I have defined my scenario in detail here
when I don't have a class library it works fine.
when I have a class library.

Create Controller and add Views to another project

Visual Studio 2015 + all updates.
Asp .Net Web application (MVC).
I start off by adding a few class libraries and separating the Asp .Net WA into layers i.e. DataAccess, Business Logic and the web project itself.
Once separated I add relevant references and everything is working as I expect it to be (i.e. the application functions as it did before I separated it into layers).
In my BL (Controllers are found here). I don't have the option to Add a Controller, like you would when right clicking the Controllers folder in the default project, so add the below line
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
to the csproj file for my class library and the Add Controller option now appears. Create a controller but throws an error which was due to not having a web.config file - add this file and all works (although it would be nice to have this library working without a web.config file).
The problem I've hit is, when the Controller is created it also adds a View template within the class library but my Views folder is located in my web project.
Have I done this wrong? Is there a workaround so when a controller is created, it also creates the Views into the correct project? Or another approach for this?
This is just a guess, but it seems like you are try to use a UI-based architectural pattern to build your business layer.
Typically, your models, views, and controllers are all maintained in the main web-app project. Any supporting functions (like your BL and DL) are added via class libraries. The Visual Studio MVC templates are built around that concept, which is why you had to manually add support with the GUID - and why it automatically creates the view.
If I may ask, why are you trying to build controllers into your BL? If you are trying to decouple your UI from your server code, perhaps WebAPI would be a better option.
UPDATE - A few helpful links
ProDinner - ASP.NET MVC Sample App
N Layered App with Entity Framework, Autofac, ASP.NET MVC and Unit Testing
Architecture Guide: ASP.NET MVC Framework + N-tier + Entity Framework and Many More
Most of your issues boil down to using the scaffold. The scaffold is great when you're just starting out or for extremely simple projects, but it quickly falls down beyond that. Specifically, adding a controller via scaffold is designed for an MVC project, so it expects to find things you'd find in an MVC project. Additionally, it creates scaffolded views in an appropriate directory in Views because, again, that's what it's designed to do.
The simplest solution, then, is to just not use the scaffolds. A controller is just a class that inherits from Controller. Nothing special there. Then, you can create the views where you want to create them.

Injection not working with imported beans in vaadin

I am new to vaadin I came from GWT based project where we have persistence and business logic as Java EE modules and web client as Java Web app. Now I have my modules ready with my app logic intact the only problem I am having now is how to inject my beans to vaadin app because using the vaadin cdi addon, I can only inject classes from the vaadin app. Is there a way I can inject my classes? I added the classes to my vaadin app as dependencies. Any help please?
This should work, but there are some issues, especially with some environments. Makes sure you use the latest Vaadin CDI release. With the current 1.0.2 there are this kind of issues with some servers, but the workaround is to upgrade the project to use explicitly DeltaSpike 1.2.1. I a helper project that does this and adds also some handy helper libraries called vaadin-java-ee-essentials. If you don't want to start using it, check its pom.xml how Deltapike version can be upgraded. An example that uses it.
If you can't make it work, let me know more about your server and setup so we can fix it.

Resources