wcf service hosted in console app

瀏覽次數:123 次
跳到第一則未讀訊息

Christian Setzkorn

未讀,
2012年8月29日 中午12:03:052012/8/29
收件者:S#arp Architecture
I am just wondering whether anyone had success with this (would also
appreciate any feedback – see code below).

I have a customised repository defined in:

Bla.Domain.Contracts.Repositories

Which is implemented in:

Bla.Tasks.Repositories

The customised repository is supposed to be constructor injected into
my wcf service:

[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Single,
InstanceContextMode = InstanceContextMode.PerCall)]
public class Service : IService
{
private readonly IXYZRepository _repository;

public Service() : base() {}

public Service(IXYZRepository XYZRepository)
{
this._repository = XYZRepository;
}
...

This does not happen! I am a bit confused about what to do/use. There
are many wcf related s#arp contribs (the northwind example is not
console hosted). Castle also seems to have some wcf stuff.

This is my current console app main (very preliminary):

private static IWindsorContainer container;

static void Main(string[] args)
{
container = new WindsorContainer();
IoCInitializer test = new IoCInitializer(container);

Initializer.Init();

using (ServiceHost consoleHost = new ServiceHost(typeof(Service)))
{
consoleHost.Open();
Console.WriteLine("Press any key to stop the singleton service ...");
Console.ReadLine();
}
}

I include code for IoCInitializer and Initializer:

// http://studentofallthings.blogspot.co.uk/2011/05/registering-sarp-architecture-contrib.html
public class IoCInitializer
{
public IoCInitializer() : this(new WindsorContainer()) { }
public IoCInitializer(IWindsorContainer container)
{
SharpArchContrib.Castle.CastleWindsor.ComponentRegistrar.AddComponentsTo(container);

AddGenericRepositoriesTo(container);
AddCustomRepositoriesTo(container);

ServiceLocator.SetLocatorProvider(() => new
WindsorServiceLocator(container));
}

private static void AddCustomRepositoriesTo(IWindsorContainer container)
{
container.Register(Classes.FromAssemblyNamed("Bla.Tasks")
.BasedOn<ICurrentRepository>()
//.LifestyleSingleton());
.LifestylePerThread());
}

private static void AddGenericRepositoriesTo(IWindsorContainer container)
{
container.Register(
Component.For(typeof(IEntityDuplicateChecker))
.ImplementedBy(typeof(EntityDuplicateChecker))
.Named("entityDuplicateChecker"));

container.Register(
Component.For(typeof(INHibernateRepository<>))
.ImplementedBy(typeof(NHibernateRepository<>))
.Named("nhibernateRepositoryType"));

container.Register(
Component.For(typeof(INHibernateRepositoryWithTypedId<,>))
.ImplementedBy(typeof(NHibernateRepositoryWithTypedId<,>))
.Named("nhibernateRepositoryWithTypedId"));

container.Register(
Component.For(typeof(ISessionFactoryKeyProvider))
.ImplementedBy(typeof(DefaultSessionFactoryKeyProvider))
.Named("sessionFactoryKeyProvider"));
}
}

public static class Initializer
{
public static void Init()
{
NHibernateSession.Init(new ThreadSessionStorage(),
new[] { "Bla.Domain.dll" },
new AutoPersistenceModelGenerator().Generate(),
"NHibernate.config");
}
}

Chris Richards

未讀,
2012年8月30日 凌晨3:46:472012/8/30
收件者:sharp-arc...@googlegroups.com
You need to make sure that the Service is resolved via Windsor:

http://bronumski.blogspot.co.uk/2009/09/using-windsor-to-inject-dependencies.html


Regards,
Chris
> --
> You received this message because you are subscribed to the Google Groups "S#arp Architecture" group.
> To post to this group, send email to sharp-arc...@googlegroups.com.
> To unsubscribe from this group, send email to sharp-architect...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sharp-architecture?hl=en.
>

Christian Setzkorn

未讀,
2012年8月30日 凌晨4:13:152012/8/30
收件者:sharp-arc...@googlegroups.com
Thanks for your reply. Its very much appreciated. Unfortunately, I am
working with version 3.1 so the static method:

DefaultServiceHostFactory.RegisterContainer(container.Kernel);

does not work anymore. See:

http://stackoverflow.com/questions/9729395/castlewindsor-3-0-and-defaultservicehostfactory-registercontainer

Did someone recently manage to integrate s#arp into a self/console-hosted wcf?

Thanks.

Chris Richards

未讀,
2012年8月30日 清晨6:17:112012/8/30
收件者:sharp-arc...@googlegroups.com
I've created a sample project that shows how to host a WCF service using Castle Windsor and SharpArch:

https://github.com/yellowfeather/TestWcfService


Regards,
Chris
30 August 2012 09:13
Thanks for your reply. Its very much appreciated. Unfortunately, I am
working with version 3.1 so the static method:

DefaultServiceHostFactory.RegisterContainer(container.Kernel);

does not work anymore. See:

http://stackoverflow.com/questions/9729395/castlewindsor-3-0-and-defaultservicehostfactory-registercontainer

Did someone recently manage to integrate s#arp into a self/console-hosted wcf?

Thanks.

On Thu, Aug 30, 2012 at 8:46 AM, Chris Richards

30 August 2012 08:46
You need to make sure that the Service is resolved via Windsor:

http://bronumski.blogspot.co.uk/2009/09/using-windsor-to-inject-dependencies.html


Regards,
Chris

29 August 2012 17:03
I am just wondering whether anyone had success with this (would also
appreciate any feedback � see code below).

Christian Setzkorn

未讀,
2012年8月30日 清晨6:35:022012/8/30
收件者:sharp-arc...@googlegroups.com
Thanks Chris - this is very much appreciated. This works.

Christian

appreciate any feedback – see code below).
postbox-contact.jpg
postbox-contact.jpg

daniel

未讀,
2014年9月29日 上午10:11:162014/9/29
收件者:sharp-arc...@googlegroups.com
Hi,
Its using Autopersistence and I haven't managed toget it tocreate the DB.

What I actually want is a sample using Sharp Arch Contrib so I can use Windsor and SharpArch persistence form a console app.
Does anyone know of such a thing? I have  found snippets form NorthWind.Console but not a compelte solution. I have found one called Phoneook that provides and example of a console app using SharpArch etc.  However I cannot manage to get the right configuration, installers etc.  so I can use it in my app. Does anyone have a different working app using SharpArch for a console app.

daniel

未讀,
2014年9月30日 凌晨2:47:452014/9/30
收件者:sharp-arc...@googlegroups.com
And of course I can simply manually create he DB which is what I did so now I just have to see if it workjs through a client
回覆所有人
回覆作者
轉寄
0 則新訊息