s#arp repository constructor injection for wcf service/client - wcf

I understand there is a s#arp contrib collection of dlls but not much documentation (as far as I can see). I intend to use the s#arp architecture in a wcf service (console app hosted). Could someone please provide some code that shows me how to (constructor) inject a repository into a wcf service/client? Is there a transaction attribute for wcf methods similar to that for controller actions in asp.net mvc? Thanks.
PS:
The northwind example:
northwind
supposedly contains an example but the downloaded vs solution does not load properly.

Haven't used WCF in a while, but follow the steps here:
https://github.com/sharparchitecture/Sharp-Architecture-Contrib/wiki/preparing-your-application-to-use-attributes-with-Castle-facilities
You need to add the initialisation code at the start of the app.
Instead of downloading the dlls, just add them using nuget. from the nuget package manager console:
install-package SharpArchContrib.Core
install-package SharpArchContrib.Domain
install-package SharpArchContrib.Castle
There is some documentation about the transaction attribute here, which should provide a starting point WCF:
https://github.com/sharparchitecture/Sharp-Architecture-Contrib/wiki/Transaction-attribute-%28supports-nhibernate-or-system.transaction.-works-with-asp.net%2C-wcf%2C-windows-gui-and-windows-service-applications%29
Chris Richards has posted an example on how to use SharpArch in WCF Console App
https://github.com/yellowfeather/TestWcfService

Related

how to develop N-Tier Layer for WCF Service by using Entity framework 6.0.. Suggest me exposing Entities as datacontract is good or bad?

Could you please help in creating N-Tier Arch for WCF Service which will uses Entity framework 6.0 for data access.
I have worked in Creating N-Tier Arch for WCF using Software factory with Enterprise library....for data access and exception logging in database as well as in file system
But am really confused whether I can expose the Entities which generated as part of the Entity framework in the WCF Service data contract... also suggest me how to implement other activities like exception logging in database using the entity framework...
If possible please guide me by creating Sample or demo N-TIER Arch for WCF using Entity framework...
I have seen lot of articles saying need to use repository pattern when using Entity framework
Do we really need to implement or use repository pattern when using Entity framework
Is using Trackable Entities a good idea for WCF? Also please explain how the Trackable Entities works?
This blog is not only about exposing entities via WCF but also about implementing business logic as part of those entities and sharing it via shared assemblies on .NET clients and servers.
Concerning n-tier architecture and respective implementation you may well be interested in using the N-Tier Entity Framework which perfectly addresses your needs. The framework provides Visual Studio templates to create required components for the different tiers. Then it provides T4 code generation templates to generate client and server code based on entity models (edmx). You may also find sample applications and a user guide for download on codeplex.
Logging exceptions and other information is done best using a logging framework like log4net or NLog. If you need to send log messages from client to server you should do so using async messaging which can be done with WCF using MSMQ binding.

Wcf.js module to access wcf services from nodejs

I have a requirement to access a wcf webservice from my node server.I came across a module called wcf.js which was rated for that purpose.But am confused with the part of message can anyone give me an explanation as how to code using that module will be really helpful.
The codeproject article at http://www.codeproject.com/Articles/379389/Wcf-js-Call-WCF-web-services-from-Node-js has some examples of how to call a WCF service using that package. And the project's page on GitHub also has some documentation.
In the GitHub project you can also find some examples, and the tests for this project (and for any project, in general) are always a good starting point to see how one would use a framework.

Selecting an IoC container for asp.net webapi

I am looking for an ioc container to use for asp.net webapi. Couple of the key feature we are looking for are as follow
Custom lifetimes
Built-in support for web request lifetime
Good integration with web api in terms of manage the dependency registration.
Mark Seemann knows his DI/Ioc and has an article on implementing it for Wep Api with Castle Windsor here. I don't know about custom lifetimes but it definitely solves the second and third requirements.
Castle is not as lightweight as say Autofac but it's been around for years and is tried and tested: I am using Castle for my Web Api and Mvc projects without issue so far.
Both should do the job though.
I personally like Unity. The reason why I use Unity is that it is build by Microsoft and with that you can expect that it is nearly up-to-date. Also I had prior experience with it and it has good support for ASP.NET Web API, but the final choice for or against a container is up to you. It really dependent on personal flavor.
There's a small part in the ASP.NET tutorials which talks about using Unity with Web API.

Handling ComplexType In Web API MVC 4

My project use Web API MVC 4 that it don't support complex type in OData query. Is there any solution to this issue?
To solving above problem, use the following steps:
Install nuget package from http://www.nuget.org/packages/Microsoft.AspNet.WebApi.OData.
Remove any configuration from Application_Start.
Add config.EnableQuerySupport() to WebApi.config.
Adding Inheritance Support to OdataModelBuilder
Users can now define abstract entity types and entity types that derive from another entity type. OData doesn't support complex type inheritance.This commit only adds support in the ModelBuilder. Support for inheritance in the ODataConventionModelBuilder, ODataMediaTypeFormatter and Query support is still pending.
To install Microsoft ASP.NET Web API OData, run the following command in the Package Manager Console :
Install-Package Microsoft.AspNet.WebApi.OData -Pre

Ninject Di bindings using a WCF service

I recently created a WCF service library. I am planning on hosting it in IIS. Since I want to reuse my repository layer I decided to go use Ninject in my WCF service as well (I use it in other projects in the solution).
I installed the Ninject Wcf Extensions. I configured it using the NinjectServiceHostFactory in the svc file. I added a Global.asax file to override the CreateKernel() that inherits from NinjectWcfApplication but I am not sure if I am using the bindings correctly. I first started with:
Bind<IUnitOfWork>().To<UnitOfWork>().InRequestScope();
But I quickly realized that this does not work since no data was saved to my database. It appears that the WCF service does not use the ASP.NET pipeline. I went ahead and tried both of these as well just to see if my data was committed to the database:
Bind<IUnitOfWork>().To<UnitOfWork>().InThreadScope();
Bind<IUnitOfWork>().To<UnitOfWork>().InTransientScope();
No luck. I then decided to try:
Bind<IUnitOfWork>().To<UnitOfWork>().InSingletonScope();
This worked but I don't want my database context to be shared by every single request that comes in to the WCF service. I then did some research and found the following approach:
Bind<IUnitOfWork>().To<UnitOfWork>().InScope(c => OperationContext.Current);
This works but is it correct? I wan t something to resemble the InRequestScope for a MVC application. Each request to the service should get its own Database context.
I suggest to have a look at the latest build from the CI-Server http://teamcity.codebetter.com
You need Ninject, Ninject.Web.Common, Ninject.Extensions.Wcf
With this version you can use InRequestScope for Wcf.
I am new to Ninject, but I can tell you that OperationContext.Current is the equivalent to HttpContext.Current for web application.
So your first thought was to use .InRequestScope(); (which is equivalent to .InScope(c => HttpContext.Current);)
so I guess that using .InScope(c => OperationContext.Current); for WCF is pretty correct.