Newsgroups: microsoft.public.dotnet.languages.csharp
From: Arne Vajhøj <a...@vajhoej.dk>
Date: Mon, 19 Nov 2012 21:38:23 -0500
Local: Mon, Nov 19 2012 9:38 pm
Subject: Re: Wire a Configuration to a Service
On 11/15/2012 6:59 AM, Shapper wrote:
> I am creating a translator as follows:
I do not see any reason why to extend the class here instead of just
> public interface ITranslator {
> Basically, this translates a string from one culture to another.
> This is working in a different way from something I asked sometime ago in this newsgroup. I hope I am able to get some advice on this version.
> I have a class which holds groups of translations:
> public class TranslatorProviderBase {
> Using this class as base I can place translations in different parts of my application:
> public class TranslatorProvider : TranslatorProviderBase {
having the client code Add to TranslatorProviderBase (which in that case probably should just be called TranslatorProvider). > I created a class to "save" the providers and the translator configuration:
What value does this class have? If none then get rid of it.
> public class TranslatorConfiguration {
> I have a class through which I configure the translator:
You translator needs to get an IList<TranslatorProviderBase> in as
> public class TranslatorManager {
> NOTE: This class will have other methods like AssertTranslatorConfigurationIsValid, etc.
> The translator setup and usage would be something like this:
> TranslatorManager.Initialize(x => {
> PROBLEMS:
> 1 - My main problem, at the moment, is how to wire the Translator, implementation of ITranslator, to the TranslatorConfiguration so I can access providers and values in Translator.
> 2 - I think I should also allow to register the container in configuration and have some kind of factory to wire things ... But I am not sure if yes and how.
> My Translator, implementation of ITranslator, is the following:
> public class Translator : ITranslator {
> public String Translate(String text, String fromCulture, String toCulture) {
> foreach (TranslatorProviderBase provider in TranslatorConfiguration.Providers) {
> Dictionary<String, String> row = provider.Table.First(x => x.Any(y => y.Key == fromCulture && y.Value == text));
> String translation;
> }
> } // Translate
> See how I am using "TranslatorConfiguration.Providers" in my foreach loop.
> Of course this does not work unless I make TranslatorConfiguration as static as well as its methods and properties.
> But then I get the following errors in TranslatorManager:
> 'TranslatorConfiguration': static types cannot be used as type arguments
> Cannot create an instance of the static class
> I have seen a few libraries 'working' this way but I am not sure how to wire the configuration values (TranslatorConfiguration) to the service (Translator).
constructor argument or via setter, save it in a field and then just use it. Arne
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||